Skip to content

Instantly share code, notes, and snippets.

@bjesus
Created August 30, 2011 13:27
Show Gist options
  • Save bjesus/1180870 to your computer and use it in GitHub Desktop.
Save bjesus/1180870 to your computer and use it in GitHub Desktop.
DocumentNotFound with nested attributes
class Account
include Mongoid::Document
field :name, :type => String
field :surname, :type => String
has_and_belongs_to_many :kenim_rakaz, :class_name => 'Ken', :inverse_of => :rakazim
end
class Ken
include Mongoid::Document
field :name, :type => String
field :code, :type => Integer
has_and_belongs_to_many :rakazim, :class_name => 'Account', :inverse_of => :kenim_rakaz, :autosave => true
accepts_nested_attributes_for :rakazim, :allow_destroy => true
end
ruby-1.8.7-p302 > values
=> {"name"=>"rama", "code"=>"1417", "rakazim_attributes"=>{"0"=>{"name"=>"john", "id"=>"4e445a36a7679b6233000002", "_destroy"=>"0", "surname"=>"smith"}}}
ruby-1.8.7-p302 > object.update_attributes values
Mongoid::Errors::DocumentNotFound: Document not found for class Account with id(s) 4e445a36a7679b6233000002.
from /home/bjesus/.rvm/gems/ruby-1.8.7-p302@notepad/gems/mongoid-2.0.0/lib/mongoid/criterion/inclusion.rb:192:in `execute_or_raise'
from /home/bjesus/.rvm/gems/ruby-1.8.7-p302@notepad/gems/mongoid-2.0.0/lib/mongoid/criterion/inclusion.rb:190:in `tap'
from /home/bjesus/.rvm/gems/ruby-1.8.7-p302@notepad/gems/mongoid-2.0.0/lib/mongoid/criterion/inclusion.rb:190:in `execute_or_raise'
from /home/bjesus/.rvm/gems/ruby-1.8.7-p302@notepad/gems/mongoid-2.0.0/lib/mongoid/criterion/inclusion.rb:106:in `find'
from /home/bjesus/.rvm/gems/ruby-1.8.7-p302@notepad/gems/mongoid-2.0.0/lib/mongoid/relations/referenced/many.rb:163:in `find'
from /home/bjesus/.rvm/gems/ruby-1.8.7-p302@notepad/gems/mongoid-2.0.0/lib/mongoid/relations/builders/nested_attributes/many.rb:117:in `process'
from /home/bjesus/.rvm/gems/ruby-1.8.7-p302@notepad/gems/mongoid-2.0.0/lib/mongoid/relations/builders/nested_attributes/many.rb:31:in `build'
from /home/bjesus/.rvm/gems/ruby-1.8.7-p302@notepad/gems/mongoid-2.0.0/lib/mongoid/relations/builders/nested_attributes/many.rb:27:in `each'
from /home/bjesus/.rvm/gems/ruby-1.8.7-p302@notepad/gems/mongoid-2.0.0/lib/mongoid/relations/builders/nested_attributes/many.rb:27:in `build'
from /home/bjesus/.rvm/gems/ruby-1.8.7-p302@notepad/gems/mongoid-2.0.0/lib/mongoid/nested_attributes.rb:45:in `rakazim_attributes='
from /home/bjesus/.rvm/gems/ruby-1.8.7-p302@notepad/gems/mongoid-2.0.0/lib/mongoid/attributes/processing.rb:110:in `send'
from /home/bjesus/.rvm/gems/ruby-1.8.7-p302@notepad/gems/mongoid-2.0.0/lib/mongoid/attributes/processing.rb:110:in `process_nested'
from /home/bjesus/.rvm/gems/ruby-1.8.7-p302@notepad/gems/mongoid-2.0.0/lib/mongoid/attributes/processing.rb:109:in `each_pair'
from /home/bjesus/.rvm/gems/ruby-1.8.7-p302@notepad/gems/mongoid-2.0.0/lib/mongoid/attributes/processing.rb:109:in `process_nested'
from /home/bjesus/.rvm/gems/ruby-1.8.7-p302@notepad/gems/mongoid-2.0.0/lib/mongoid/attributes/processing.rb:121:in `process_pending'
from /home/bjesus/.rvm/gems/ruby-1.8.7-p302@notepad/gems/mongoid-2.0.0/lib/mongoid/attributes/processing.rb:28:in `process'
from /home/bjesus/.rvm/gems/ruby-1.8.7-p302@notepad/gems/mongoid-2.0.0/lib/mongoid/attributes.rb:112:in `write_attributes'
from /home/bjesus/.rvm/gems/ruby-1.8.7-p302@notepad/gems/mongoid-2.0.0/lib/mongoid/persistence.rb:117:in `update_attributes'
from (irb):187
from :0
ruby-1.8.7-p302 > Account.find("4e445a36a7679b6233000002")
=> #<Account _id: 4e445a36a7679b6233000002, name: "רכז קן", crypted_password: "$2a$10$4HxIK0j99pBB9/AWfdjDSuWtGhOwXKvRqk5J0vSnNeO/Q1oIO4q2K", role: "rakaz_ken", _id: BSON::ObjectId('4e445a36a7679b6233000002'), _type: nil, tz: nil, kenim_rakaz_ids: [], birthday: nil, surname: "", email: "raken@gmail.com">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment