Class: ActiveRecord::Associations::Preloader::HasMany
- Inherits:
-
Object
- Object
- ActiveRecord::Associations::Preloader::HasMany
- Defined in:
- lib/includes_many/active_record32/has_many.rb,
lib/includes_many/active_record40/has_many.rb,
lib/includes_many/active_record41/has_many.rb,
lib/includes_many/active_record42/has_many.rb
Instance Method Summary collapse
-
#association_key_name ⇒ Object
method is fully rewritten.
-
#owners_by_key ⇒ Object
method is fully rewritten.
Instance Method Details
#association_key_name ⇒ Object
method is fully rewritten
8 9 10 11 12 13 14 15 |
# File 'lib/includes_many/active_record32/has_many.rb', line 8 def association_key_name fk = reflection.foreign_key if fk.respond_to?(:call) fk.call(owners.first) else fk end end |
#owners_by_key ⇒ Object
method is fully rewritten
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/includes_many/active_record32/has_many.rb', line 20 def owners_by_key @owners_by_key ||= begin res = Hash.new { |h,k| h[k] = Set.new } owners.each do |owner| key = if owner_key_name.respond_to?(:call) owner_key_name.call(owner) else owner[owner_key_name] end if key.respond_to?(:each) key.each { |k| res[k && k.to_s] << owner } else res[key && key.to_s] << owner end end res end end |