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

cascade_callbacks not working using before_create and <<

    • Fully Compatible

      I experienced the following behavior:

      class Parent
          include Mongoid::Document
      
          embeds_many :things, :cascade_callbacks => true
      
          before_create :initialize_first_thing
      
          def initialize_first_thing
              self.things << Thing.new(:name => "first")
          end
      end
      
      class Thing
          include Mongoid::Document
          include Mongoid::Timestamps
      
          embedded_in :parent
      
          field :name, :type => String
      
          before_create lambda {puts "before_create"}
      end
      

      When I create the parent, the before_create on Thing does not run, neither the timestamps are saved.

      Am I missing something?

            Assignee:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Reporter:
            rafaels rafaels
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: