123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::Relation::HashMerger

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: activerecord/lib/active_record/relation/merger.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(relation, hash, rewhere = nil) ⇒ HashMerger

[ GitHub ]

  
# File 'activerecord/lib/active_record/relation/merger.rb', line 10

def initialize(relation, hash, rewhere = nil)
  hash.assert_valid_keys(*Relation::VALUE_METHODS)

  @relation = relation
  @hash     = hash
  @rewhere  = rewhere
end

Instance Attribute Details

#hash (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/relation/merger.rb', line 8

attr_reader :relation, :hash

#relation (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/relation/merger.rb', line 8

attr_reader :relation, :hash

Instance Method Details

#merge

[ GitHub ]

  
# File 'activerecord/lib/active_record/relation/merger.rb', line 18

def merge
  Merger.new(relation, other, @rewhere).merge
end

#other

Applying values to a relation has some side effects. E.g. interpolation might take place for where values. So we should build a relation to merge in rather than directly merging the values.

[ GitHub ]

  
# File 'activerecord/lib/active_record/relation/merger.rb', line 26

def other
  other = Relation.create(
    relation.klass,
    table: relation.table,
    predicate_builder: relation.predicate_builder
  )
  hash.each do |k, v|
    k = :_select if k == :select
    if Array === v
      other.public_send("#{k}!", *v)
    else
      other.public_send("#{k}!", v)
    end
  end
  other
end