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

Override shared attributes in criteria's selector with a write method's attributes

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 6.0.0
    • Affects Version/s: None
    • Component/s: None
    • None

      When methods are chained on a criteria, the write method's attributes should override shared attributes in the criteria's selector. This is the behavior of ActiveRecord and should be emulated in Mongoid.

      In ActiveRecord:

      query = Article.where(title: 'ABC')
      query.find_or_create_by(title: 'XYZ', text: 'something')
       => #<Article id: 4, title: "XYZ", text: "something"
      

      In Mongoid:

      query = Article.where(title: 'ABC')
      query.find_or_create_by(title: 'XYZ', text: 'something')
      => #<Article _id: ...., title: "ABC", text: "something"> # title should be 'XYZ'
      

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            emily.stolfo Emily Stolfo
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: