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

update_attributes for embedded object with accepts_nested_attributes_for doesn't fire after_create

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

      When creating a nested object using

      Unable to find source-code formatter for language: update_attributes```. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      , 

      after_create

       is not called.
      Example:
      

      rb

      class XComment
      include Mongoid::Document
      field :msg
      embedded_in :test_user

      after_create do
      print 'Should get here Should get here Should get here Should get here Should get here Should get here '
      end
      end

      class TestUser
      include Mongoid::Document
      embeds_many :x_comments
      accepts_nested_attributes_for :x_comments, allow_destroy: true
      end

      u=TestUser.create!()

      Not showing the print

      u.update_attributes(x_comments_attributes: [

      {msg: 'malicious message'}

      ])

      This however works just fine

      comment = u.x_comments.create!(msg: 'Hello')
      `

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

              Created:
              Updated:
              Resolved: