Module: Mongoid::Association::Referenced::WithPolymorphicCriteria Private
Do not use. This module is for internal use only.
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/mongoid/association/referenced/with_polymorphic_criteria.rb |
Overview
Implements the with_polymorphic_criteria
shared behavior.
Instance Method Summary
-
#with_polymorphic_criterion(criteria, base) ⇒ Mongoid::Criteria
Internal use only
If the receiver represents a polymorphic association, applies the polymorphic search criteria to the given
criteria
object.
Instance Method Details
#with_polymorphic_criterion(criteria, base) ⇒ Mongoid::Criteria
If the receiver represents a polymorphic association, applies the polymorphic search criteria to the given criteria
object.
# File 'lib/mongoid/association/referenced/with_polymorphic_criteria.rb', line 20
def with_polymorphic_criterion(criteria, base) if polymorphic? # 1. get the resolver for the inverse association resolver = klass.reflect_on_association(as).resolver # 2. look up the list of keys from the resolver, given base keys = resolver.keys_for(base) # 3. use equality if there is just one key, `in` if there are multiple if keys.many? criteria.where(type => { :$in => keys }) else criteria.where(type => keys.first) end else criteria end end