I should add that I also tried making a custom:

  validate :validate_tasks

routine in the Project model.  In that routine I explicitly
walk through the child tasks, call valid? on each one, and if
any are not valid, I add a sensible single error message to
:base on the Project.

It works, I get the :base error fine, but I still get the slew
of "is invalid" errors for each invalid task.  I thought that
was what "validates_associated" was supposed to do for me, but
I'm not calling validates_associated... ?

        -glenn

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
-~----------~----~----~----~------~----~------~--~---

Reply via email to