Class: ActiveRecord::Relation::HashMerger
- Inherits:
-
Object
- Object
- ActiveRecord::Relation::HashMerger
- Defined in:
- lib/active_record/relation/merger.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#relation ⇒ Object
readonly
Returns the value of attribute relation.
Instance Method Summary collapse
-
#initialize(relation, hash) ⇒ HashMerger
constructor
A new instance of HashMerger.
-
#merge ⇒ Object
:nodoc:.
-
#other ⇒ Object
Applying values to a relation has some side effects.
Constructor Details
#initialize(relation, hash) ⇒ HashMerger
Returns a new instance of HashMerger.
10 11 12 13 14 15 |
# File 'lib/active_record/relation/merger.rb', line 10 def initialize(relation, hash) hash.assert_valid_keys(*Relation::VALUE_METHODS) @relation = relation @hash = hash end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
8 9 10 |
# File 'lib/active_record/relation/merger.rb', line 8 def hash @hash end |
#relation ⇒ Object (readonly)
Returns the value of attribute relation.
8 9 10 |
# File 'lib/active_record/relation/merger.rb', line 8 def relation @relation end |
Instance Method Details
#merge ⇒ Object
:nodoc:
17 18 19 |
# File 'lib/active_record/relation/merger.rb', line 17 def merge #:nodoc: Merger.new(relation, other).merge end |
#other ⇒ Object
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.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/active_record/relation/merger.rb', line 25 def other other = Relation.create( relation.klass, table: relation.table, predicate_builder: relation.predicate_builder ) hash.each { |k, v| if k == :joins if Hash === v other.joins!(v) else other.joins!(*v) end elsif k == :select other._select!(v) else other.send("#{k}!", v) end } other end |