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

#new does not behave the same as #build on Criteria

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.0.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      Consider the following example:

      require 'mongoid'
      class Car
      include Mongoid::Document
      field :make, type: String
      end
      Car.where(:make => "Toyota").build

      1. => #<Car _id: 4fe08a81bb21c7ba19000001, _type: nil, make: "Toyota">
        Car.where(:make => "Toyota").new
      2. => #<Car _id: 4fe08a81bb21c7ba19000002, _type: nil, make: nil>

      On Many and ManyToMany relations, #new is aliased to #build, but not on Criteria, which makes the behaviour confusing.

      I get the same results with Mongoid 2.4.10 and 3.0.0.rc.

            Assignee:
            Unassigned Unassigned
            Reporter:
            rkistner rkistner
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: