that's interesting. i would have expected what you did too, but that's not the default behavior of has_many.
http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html has_many(association_id, options = {}, &extension) ... Supported options ... :validate If false, don‘t validate the associated objects when saving the parent object. true by default. so looks like has_many tasks :default => false will get what you're looking for. On Jul 13, 2009, at 6:15 PM, Glenn Little wrote: > > I've got something like this: > > Project has_many tasks > Task belongs_to project > > I have simple validation in each. The problem is, if I do something > like: > > p = Project.new > p.tasks.build # <-- not valid because of blank field > p.tasks.build > p.tasks.build > > p.valid? -> false > > All good so far. But if I look at the errors on p: > > y p.errors > > I see something like: > > errors: > name: > - can't be blank # this is fine > tasks: > - is invalid > - is invalid > - is invalid # these, not so much > > I do not have a call to "validates_associated" in my Project model, so > why is it picking up errors on the associated objects? > > Thanks in advance... > > -glenn > > > --~--~---------~--~----~------------~-------~--~----~ SD Ruby mailing list [email protected] http://groups.google.com/group/sdruby -~----------~----~----~----~------~----~------~--~---
