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

accepts_nested_attributes_for with embeds_one update

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

      I have the following models:

      class Temp
        include Mongoid::Document
        include Mongoid::Timestamps
      
        field :name
        embeds_one :temp_em
      
        accepts_nested_attributes_for :temp_em
      end
      
      class TempEm
        include Mongoid::Document
        include Mongoid::Timestamps
      
        field :some
      end
      

      And i want to update or create embedded document(TempEm)

       ruby
      t = Temp.find_or_create_by(:name => 'test')
      t.update_attributes!(:temp_em_attributes => {:some => 'some name8'}) 
      p t.temp_em 
      t.reload 
      t.temp_em
      

      After first call it works ok. TempEm was created with correct field :some
      In second call modify :some to "some other value" and it should be updated but is not.

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

              Created:
              Updated:
              Resolved: