Class: Mongoid::ActiveRecord::EagerLoadable::RelationMetadata
- Inherits:
-
Object
- Object
- Mongoid::ActiveRecord::EagerLoadable::RelationMetadata
- Defined in:
- lib/mongoid/active_record/eager_loadable/relation_metadata.rb
Instance Attribute Summary collapse
-
#relation ⇒ Object
readonly
Returns the value of attribute relation.
Instance Method Summary collapse
- #eager_load(ids) ⇒ Object
- #foreign_key ⇒ Object
-
#initialize(relation) ⇒ RelationMetadata
constructor
A new instance of RelationMetadata.
- #relation_class ⇒ Object
- #stores_foreign_key? ⇒ Boolean
Constructor Details
#initialize(relation) ⇒ RelationMetadata
Returns a new instance of RelationMetadata.
8 9 10 11 |
# File 'lib/mongoid/active_record/eager_loadable/relation_metadata.rb', line 8 def initialize(relation) @relation = relation relation_class.define_singleton_method(:collection_name) { table_name } end |
Instance Attribute Details
#relation ⇒ Object (readonly)
Returns the value of attribute relation.
6 7 8 |
# File 'lib/mongoid/active_record/eager_loadable/relation_metadata.rb', line 6 def relation @relation end |
Instance Method Details
#eager_load(ids) ⇒ Object
13 14 15 16 17 |
# File 'lib/mongoid/active_record/eager_loadable/relation_metadata.rb', line 13 def eager_load(ids) relation_class.where(id: ids.uniq).each do |record| IdentityMap.set(record) end end |
#foreign_key ⇒ Object
23 24 25 |
# File 'lib/mongoid/active_record/eager_loadable/relation_metadata.rb', line 23 def foreign_key "#{relation}_id" end |
#relation_class ⇒ Object
19 20 21 |
# File 'lib/mongoid/active_record/eager_loadable/relation_metadata.rb', line 19 def relation_class relation.to_s.classify.constantize end |
#stores_foreign_key? ⇒ Boolean
27 28 29 |
# File 'lib/mongoid/active_record/eager_loadable/relation_metadata.rb', line 27 def stores_foreign_key? true end |