lib/mongoid/criteria/queryable/selector.rb
# Evolve a single key selection with range values. This method traverses
# the association tree to build a query for the given value and
# serializer. There are three parts to the query here:
#
# (1) "klass.child.gchild" => {
#       "$elemMatch" => {
#     (2) "ggchild.field" => (3) { "$gte" => 6, "$lte" => 10 }
#       }
#     }
# (1) The first n fields are dotted together until the last
#     embeds_many or field of type array. In the above case, gchild
#     would be an embeds_many or Array, and ggchild would be an
#     embeds_one or a hash.
# (2) The last fields are used inside the $elemMatch. This one is
#     actually optional, and will be ignored if the last field is an
#     array or embeds_many. If the last field is an array (1), (2) and
#     (3) will look like:
#
#       "klass.child.gchild.ggchild.field" => {
#         { "$elemMatch" => { "$gte" => 6, "$lte" => 10 } }
#       }
#
# (3) This is calculated by:
#
#       value.__evolve_range__(serializer: serializer).
#
# @api private
#
# @param [ String ] key The to store the range for.
# @param [ Object ] serializer The optional serializer for the field.
# @param [ Range ] value The Range to serialize.
#
# @return [ Array<String, Hash> ] The store name and serialized Range.
Evolve a single key selection with range values. This method traverses
the association tree to build a query for the given value and
serializer. There are three parts to the query here.





(3) This is calculated by.


Evolve a single key selection with range values . This method traverses the association tree to build a query for the given value and serializer . There are three parts to the query here . ( 3 ) This is calculated by .
def evolve_range(key, serializer, value)
          v = value.__evolve_range__(serializer: serializer)
          assocs = []
          Fields.traverse_association_tree(key, serializers, associations, aliased_associations) do |meth, obj, is_field|
            assocs.push([meth, obj, is_field])
          end
          inner_key = ""
          loop do
            return [ key, v ] if assocs.empty?
            meth, obj, is_field = assocs.last
            break if (is_field && obj.type == Array) || (!is_field && obj.is_a?(Association::Embedded::EmbedsMany))
            assocs.pop
            inner_key = "#{meth}.#{inner_key}"
          end
          if inner_key.blank?
            [ key, { "$elemMatch" => v }]
          else
            store_key = assocs.map(&:first).join('.')
            store_value = { "$elemMatch" => { inner_key.chop => v } }
            [ store_key,  store_value ]
          end
        end
def evolve_range ( key , serializer , value ) v = value . __evolve_range__ ( serializer : serializer ) assocs = [ ] Fields . traverse_association_tree ( key , serializers , associations , aliased_associations ) do | meth , obj , is_field | assocs . push ( [ meth , obj , is_field ] ) end inner_key = "" loop do return [ key , v ] if assocs . empty? meth , obj , is_field = assocs . last break if ( is_field && obj . type == Array ) || ( ! is_field && obj . is_a? ( Association :: Embedded :: EmbedsMany ) ) assocs . pop inner_key = "#{meth}.#{inner_key}" end if inner_key . blank? [ key , { "$elemMatch" => v } ] else store_key = assocs . map ( & :first ) . join ( '.' ) store_value = { "$elemMatch" => { inner_key . chop => v } } [ store_key , store_value ] end end
Evolve a single key selection with range values.
Evolve a single key selection with range values .
# Iterate backwards until you get a field with type # Array or an embeds_many association. # If there are no arrays or embeds_many associations, just return # the key and value without $elemMatch. # If the last array or embeds_many association is the last field, # the inner key (2) is ignored, and the outer key (1) is the original # key.
The store name and serialized Range.
The store name and serialized Range .
 Array<String, Hash> 
key
<not_specific>
serializer
<not_specific>
value
<not_specific>
<not_specific>
value The Range to serialize.
value The Range to serialize .
api
None