Class: ActiveRecord::DisableJoinsAssociationRelation
- Defined in:
- activerecord/lib/active_record/disable_joins_association_relation.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#ids ⇒ Object
readonly
Returns the value of attribute ids.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #first(limit = nil) ⇒ Object
-
#initialize(klass, key, ids) ⇒ DisableJoinsAssociationRelation
constructor
A new instance of DisableJoinsAssociationRelation.
- #limit(value) ⇒ Object
- #load ⇒ Object
Constructor Details
#initialize(klass, key, ids) ⇒ DisableJoinsAssociationRelation
Returns a new instance of DisableJoinsAssociationRelation.
7 8 9 10 11 |
# File 'activerecord/lib/active_record/disable_joins_association_relation.rb', line 7 def initialize(klass, key, ids) @ids = ids.uniq @key = key super(klass) end |
Instance Attribute Details
#ids ⇒ Object (readonly)
Returns the value of attribute ids
5 6 7 |
# File 'activerecord/lib/active_record/disable_joins_association_relation.rb', line 5 def ids @ids end |
#key ⇒ Object (readonly)
Returns the value of attribute key
5 6 7 |
# File 'activerecord/lib/active_record/disable_joins_association_relation.rb', line 5 def key @key end |
Instance Method Details
#first(limit = nil) ⇒ Object
17 18 19 20 21 22 23 |
# File 'activerecord/lib/active_record/disable_joins_association_relation.rb', line 17 def first(limit = nil) if limit records.limit(limit).first else records.first end end |
#limit(value) ⇒ Object
13 14 15 |
# File 'activerecord/lib/active_record/disable_joins_association_relation.rb', line 13 def limit(value) records.take(value) end |
#load ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'activerecord/lib/active_record/disable_joins_association_relation.rb', line 25 def load super records = @records records_by_id = records.group_by do |record| record[key] end records = ids.flat_map { |id| records_by_id[id] } records.compact! @records = records end |