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

Updating embedded documents by passing a hash of values

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

      I think it's a bit counterintuitive that you can do this:

      Parent.create(:child => { :field => :value })

      but you can't do the same when updating:

      parent_object.update_attributes(:child => { :field => :value }) (method 1)

      Instead, you have to declare it with accepts_nested_attributes_for :child and call

      parent_object.update_attributes(:child_attributes => { :field => :value }) (method 2)

      I've forked mongoid and added some changes to allow updating embedded documents through method (1). allow_nested_attributes_for doesn't seem to apply to MongoDB's embedded documents.

      Here's the link:

      http://github.com/evansagge/mongoid/commit/6dc0af5

            Assignee:
            Unassigned Unassigned
            Reporter:
            evansagge Evan Sagge
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: