Class: ActiveAny::Associations::Preloader::BelongsTo
- Inherits:
-
Association
- Object
- Association
- ActiveAny::Associations::Preloader::BelongsTo
- Defined in:
- lib/active_any/associations/preloader/belongs_to.rb
Instance Attribute Summary
Attributes inherited from Association
#inversed, #loaded, #owner, #reflection, #target
Instance Method Summary collapse
Methods inherited from Association
#association_scope, #find_from_target?, #find_target, #initialize, #klass, #load_target, #loaded!, #loaded?, #reader, #reload, #reset, #reset_scope, #scope, #set_inverse_instance, #target_scope, #writer
Constructor Details
This class inherits a constructor from ActiveAny::Associations::Association
Instance Method Details
#association_key_name ⇒ Object
16 17 18 |
# File 'lib/active_any/associations/preloader/belongs_to.rb', line 16 def association_key_name reflection.[:primary_key] || klass && klass.primary_key end |
#owner_key_name ⇒ Object
20 21 22 |
# File 'lib/active_any/associations/preloader/belongs_to.rb', line 20 def owner_key_name reflection.foreign_key end |
#preload(preloader) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/active_any/associations/preloader/belongs_to.rb', line 7 def preload(preloader) associated_records_by_owner(preloader).each do |owner, associated_records| record = associated_records.first association = owner.association(reflection.name) association.target = record end end |