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

accepts_nested_attributes_for saves upon assignment to _attributes

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

      Given

      class Project
        include Mongoid::Document
      
        field :title
      
        references_many :tasks, :dependent => :destroy, :autosave => false
      
        accepts_nested_attributes_for :tasks, :allow_destroy => true
      end
      

      and

      class Task
        include Mongoid::Document
      
        field :title
      
        referenced_in :project
      end
      

      Then in a console doing:

      >> project = Project.create!
      >> project.tasks_attributes = [{:title => "Task title"}]
      >> p Project.first.tasks
      [#<Task _id: 4ed5e87d662e0c6f76000002, title: "Task title", project_id: BSON::ObjectId('4ed5e83b662e0c6f76000001')>]
      

      Surely it shouldn't save until I actually call save, right? At least that's the AR way so this is leaving me to think this is a bug.

      ruby 1.8.7p352 - mongoid 2.3.4 - rails 3.1.1

            Assignee:
            Unassigned Unassigned
            Reporter:
            wulffeld Martin Moen Wulffeld
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: