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

if the before_save method returns false, then the callback will return false as well

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

      I have a model like this:

      class Model
        include Mongoid::Document
        
        field :a
        field :b
        field :is_a_equal_b type: Boolean
      
        before_save :update_is_a_equal_b
        def update_is_a_equal_b
          self.is_a_equal_b = (self.a == self.b)
        end
      end
      

      In this case, whenever a is not equal to b in this class, the update will fail due to callback is false. So what I did to fix this is:

        def update_is_a_equal_b
          self.is_a_equal_b = (self.a == self.b)
          true
        end
      

      I think this should be a bug.

            Assignee:
            Unassigned Unassigned
            Reporter:
            benzheren Ben Hu
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: