Method: NoBrainer::Document::Association::HasMany::Metadata#inverses
- Defined in:
- lib/no_brainer/document/association/has_many.rb
#inverses ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/no_brainer/document/association/has_many.rb', line 33 def inverses # We can always infer the inverse association of a has_many relationship, # because a belongs_to association cannot have a scope applied on the # selector. # XXX Without caching, this is going to get CPU intensive quickly, but # caching is hard (rails console reload, etc.). target_model..values.select do |assoc| assoc.is_a?(NoBrainer::Document::Association::BelongsTo::Metadata) and assoc.foreign_key == foreign_key and assoc.primary_key == primary_key and assoc.target_model(target_model).root_class == owner_model.root_class end end |