mongoid/mongoid — Issue #1600: 'validates_uniqueness_of' regression in 2.4.1
Author: Pesa
Created: 2012-01-16 00:04:53+00:00
State: open

```ruby
class A
include Mongoid::Document

embeds_many :bs

def explode!(c)
bs.create!(c: c)
end
end

class B
include Mongoid::Document

embedded_in :a
belongs_to :c

validates_uniqueness_of :c
end

class C
include Mongoid::Document
end
```

The reduced testcase above was working fine in 2.4.0, now it fails with:

NoMethodError: undefined method `c_changed?' for #
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.4.1/lib/mongoid/attributes.rb:166:in `method_missing'
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.4.1/lib/mongoid/validations/uniqueness.rb:44:in `validate_each'
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/activemodel-3.1.3/lib/active_model/validator.rb:153:in `block in validate'
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/activemodel-3.1.3/lib/active_model/validator.rb:150:in `each'
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/activemodel-3.1.3/lib/active_model/validator.rb:150:in `validate'
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:302:in `_callback_before_244'
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:395:in `_run_validate_callbacks'
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.4.1/lib/mongoid/callbacks.rb:43:in `block in run_callbacks'
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.4.1/lib/mongoid/callbacks.rb:68:in `call'
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.4.1/lib/mongoid/callbacks.rb:68:in `run_cascading_callbacks'
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.4.1/lib/mongoid/callbacks.rb:42:in `run_callbacks'
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/activemodel-3.1.3/lib/active_model/validations.rb:212:in `run_validations!'
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/activemodel-3.1.3/lib/active_model/validations/callbacks.rb:53:in `block in run_validations!'
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:390:in `_run_validation_callbacks'
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/callbacks.rb:81:in `run_callbacks'
... 9 levels...
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.4.1/lib/mongoid/persistence/insertion.rb:22:in `tap'
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.4.1/lib/mongoid/persistence/insertion.rb:22:in `prepare'
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.4.1/lib/mongoid/persistence/operations/embedded/insert.rb:30:in `persist'
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.4.1/lib/mongoid/persistence.rb:49:in `insert'
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.4.1/lib/mongoid/persistence.rb:154:in `upsert'
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.4.1/lib/mongoid/persistence.rb:75:in `save!'
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.4.1/lib/mongoid/relations/embedded/many.rb:157:in `block in create!'
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.4.1/lib/mongoid/relations/embedded/many.rb:157:in `tap'
from /Users/davide/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.4.1/lib/mongoid/relations/embedded/many.rb:157:in `create!'
from (irb):7:in `explode!'
from (irb):30