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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.0.0
    • Component/s: None
    • Labels:
      None
    • Sprint:
      Ruby Sprint 34

      Description

      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'
      

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: