mongoid/mongoid — Issue #1340: Habtm and has_many relations not being validated
Author: bensymonds
Created: 2011-10-10 22:35:14+00:00
State: open

... as it states on http://mongoid.org/docs/relations/validations.html

```ruby
class Thing
include Mongoid::Document
embeds_many :ems
embeds_one :eo
has_many :hms
has_one :ho
has_and_belongs_to_many :habtms
end
class Em; include Mongoid::Document; embedded_in :thing; end
class Eo; include Mongoid::Document; embedded_in :thing; end
class Hm; include Mongoid::Document; belongs_to :thing; end
class Ho; include Mongoid::Document; belongs_to :thing; end
class Habtm; include Mongoid::Document; has_and_belongs_to_many :things; end

[Thing, Em, Eo, Hm, Ho, Habtm].each do |klass|
klass.before_validation {puts "** validating #{self.class}" }
end

em = Em.new
eo = Eo.new
t = Thing.create! :ems => [em], :eo => eo
t.hms.create!
t.create_ho
t.habtms.create!
```

(Sorry about the awful class/relation names.) Then:

```
> t.reload.valid?
** validating Thing
** validating Em
** validating Eo
** validating Ho
=> true
```

So the ```habtm``` and ```hm``` are not validated.