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

Error when updating nested attributes on embedded model w/ cascade_callbacks + Timestamps

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

      This scenario fails with a cryptic error:

      NoMethodError: undefined method `each' for 2013-05-30 00:43:26 UTC:Time
      C:/ruby/lib/ruby/gems/1.9.1/gems/mongoid-3.1.4/lib/mongoid/atomic/modifiers.rb:121:in `add_operation'
      
      require 'spec_helper'
      
      describe Mongoid::History do
      
        class Post
          include Mongoid::Document
          include Mongoid::Timestamps
      
          field :title
          embeds_many :tags, :cascade_callbacks => true
      
          accepts_nested_attributes_for :tags, :allow_destroy => true
        end
      
        class Tag
          include Mongoid::Document
          include Mongoid::Timestamps
      
          field :title
        end
      
        before(:each) do
          @post= Post.create(:title => "Test")
          @tag_bar = @post.tags.create(:title => "bar")
        end
      
        it "should allow an update through the parent model" do
          update_hash = { "post" => { "tags_attributes" => { "1234" => { "id" => @tag_bar.id, "title" => "baz" } } } }
          @post.update_attributes(update_hash["post"])
          @post.tags.last.title.should == "baz"
        end
      
      end
      

      Two things seem to fix it:

      • Remove include Mongoid::Timestamps from Tag class OR
      • Remove :cascade_callbacks => true from embeds_many :tags

            Assignee:
            Unassigned Unassigned
            Reporter:
            johnnyshields Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: