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

reject_if on nested attributes don't work as expected (fix included)

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

      Since I don't have full insight into Mongoid I don't know if this would break something else, but hopefully this is good and can be included in the codebase. I have tested it and its working nicely in my app. Hopefully it can be of use for more people. Also, good job on Mongoid. It's an excellent tool, keep up the good work!

      With this fix the proc in reject_if takes one argument, a hash with all nested attributes. The entire object (all attributes) is rejected if the proc returns true, otherwise the attributes are accepted.

      Before the reject would strip out individual attributes that returned false. That behavior is different from how active record works and also inconsistent with what's expected of :reject_if.

      Code that fixes this problem: https://gist.github.com/029d4158174da4d7fb19

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

              Created:
              Updated:
              Resolved: