lib/mongoid/fields.rb
# Traverse down the association tree and search for the field for the
# given key. To do this, split the key by '.' and for each part (meth) of
# the key:
#
# - If the meth is a field, yield the meth, field, and is_field as true.
# - If the meth is an association, update the klass to the association's
#   klass, and yield the meth, klass, and is_field as false.
#
# The next iteration will use klass's fields and associations to continue
# traversing the tree.
#
# @param [ String ] key The key used to search the association tree.
# @param [ Hash ] fields The fields to begin the search with.
# @param [ Hash ] associations The associations to begin the search with.
# @param [ Hash ] aliased_associations The alaised associations to begin
#   the search with.
# @param [ Proc ] block The block takes in three paramaters, the current
#   meth, the field or the relation, and whether the second parameter is a
#   field or not.
#
# @return [ Field ] The field found for the given key at the end of the
#   search. This will return nil if the last thing found is an association
#   or no field was found for the given key.
#
# @api private
Traverse down the association tree and search for the field for the
given key. To do this, split the key by '.' and for each part (meth) of
the key.

If the meth is a field, yield the meth, field, and is_field as true.
If the meth is an association, update the klass to the association's
klass, and yield the meth, klass, and is_field as false.

The next iteration will use klass's fields and associations to continue
traversing the tree.
Traverse down the association tree and search for the field for the given key . To do this split the key by ' . ' and for each part ( meth ) of the key . If the meth is a field yield the meth field and is_field as true . If the meth is an association update the klass to the association ' s klass and yield the meth klass and is_field as false . The next iteration will use klass ' s fields and associations to continue traversing the tree .
def traverse_association_tree(key, fields, associations, aliased_associations)
        klass = nil
        field = nil
        key.split('.').each_with_index do |meth, i|
          fs = i == 0 ? fields : klass&.fields
          rs = i == 0 ? associations : klass&.relations
          as = i == 0 ? aliased_associations : klass&.aliased_associations
          aliased = meth
          if as && a = as.fetch(meth, nil)
            aliased = a.to_s
          end
          field = nil
          klass = nil
          if fs && f = fs[aliased]
            field = f
            yield(meth, f, true) if block_given?
          elsif rs && rel = rs[aliased]
            klass = rel.klass
            yield(meth, rel, false) if block_given?
          else
            yield(meth, nil, false) if block_given?
          end
        end
        field
      end
def traverse_association_tree ( key , fields , associations , aliased_associations ) klass = nil field = nil key . split ( '.' ) . each_with_index do | meth , i | fs = i == 0 ? fields : klass &. fields rs = i == 0 ? associations : klass &. relations as = i == 0 ? aliased_associations : klass &. aliased_associations aliased = meth if as && a = as . fetch ( meth , nil ) aliased = a . to_s end field = nil klass = nil if fs && f = fs [ aliased ] field = f yield ( meth , f , true ) if block_given? elsif rs && rel = rs [ aliased ] klass = rel . klass yield ( meth , rel , false ) if block_given? else yield ( meth , nil , false ) if block_given? end end field end
Traverse down the association tree and search for the field for the
given key.
Traverse down the association tree and search for the field for the given key .
# Associations can possibly have two "keys", their name and their alias. # The fields name is what is used to store it in the klass's relations # and field hashes, and the alias is what's used to store that field # in the database. The key inputted to this function is the aliased # key. We can convert them back to their names by looking in the # aliased_associations hash.
The field found for the given key at the end of the search. This will return nil if the last thing found is an association or no field was found for the given key.
The field found for the given key at the end of the search . This will return nil if the last thing found is an association or no field was found for the given key .
 Field 
key
<not_specific>
fields
<not_specific>
associations
<not_specific>
aliased_associations
<not_specific>
<not_specific>
block The block takes in three paramaters, the current meth, the field or the relation, and whether the second parameter is a field or not.
block The block takes in three paramaters the current meth the field or the relation and whether the second parameter is a field or not .
api
None