Class: ActiveRecord::DisableJoinsAssociationRelation

Inherits:
Relation show all
Defined in:
activerecord/lib/active_record/disable_joins_association_relation.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#idsObject (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

#keyObject (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

#loadObject



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