-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
Consider:
class Parent
include Mongoid::Document
field :name
references_many :children
validates_presence_of :name
end
class Child
include Mongoid::Document
field :name
referenced_in :parent, :inverse_of => :children
validates_presence_of :name
end
p = Parent.new
c = Child.new
p.children << c
p.save
In this scenario, c.errors is empty. I believe validations are just not being run unless the parent passes. That presents issues when coding forms: if you save the form blank, you get errors on parent but not on child. If you fill out the parent and save again, then the child errors appear. It is a better experience for the user to see them all at once.