Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-5122

Mongoize embedded fields in the criteria selector

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 8.0.1
    • Affects Version/s: None
    • Component/s: Attributes, Query

      Although Mongoid takes into account the the type of the fields defined in a class to build the Queries selectors, it fails to take into account the embedded records' attributes type.  See the example below:

      class Person
        include Mongoid::Document
      
        field :name, type: String
        field :age, type: Integer
      
        embeds_one :address
        accepts_nested_attributes_for :address
      end
      
      class Address
        include Mongoid::Document
      
        field :zip_code, type: String
        field :number, type: Integer
      
        embedded_in :company
      end
      
      query = Person.where(age: "28", "address.number" => "1000", "address.zip_code" => "72000-123")
      # => #<Mongoid::Criteria
      # selector: {"age"=>28, "address.number"=>"1000", "address.zip_code"=>"72000-123"}
      # options:  {}
      # class:    Person
      # embedded: false>
      

      Since Mongoid provides a clean interface for querying objects based on embedded records' attributes, I was expecting it to consider the types of embedded class fields, although this behavior is not explicitly documented.

      However, I'm not sure whether this should be considered a bug or a new feature 

      Thanks in advance.

            Assignee:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Reporter:
            arthurmde@gmail.com Arthur Del Esposte
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: