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

Repeatedly call validate method ?

    • Type: Icon: Task Task
    • Resolution: Done
    • 4.0.0 final
    • Affects Version/s: None
    • Component/s: None

      Hi there, here is my test code:

      class A
        include Mongoid::Document
        
        embeds_many :bs, cascade_callbacks: true
      end
      
      class B
        include Mongoid::Document
      
        embedded_in :a
      
        validate { puts "validate from B object" }
      end
      
      a = A.new
      a.bs.build()
      a.valid?
      
      # Output
      Validate from B object
      Validate from B object
      =>  true
      

      The validate method has been called twice. After I removing the cascade_callbacks: true option, it seems work well.

      I don't think there is any need to call the validate method repeatedly.

            Assignee:
            durran Durran Jordan
            Reporter:
            zhouguangming zhouguangming
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: