On Sun, Feb 6, 2011 at 2:10 PM, Rainer Frey <[email protected]> wrote:

> Unfortunately the Rails Guide on Active Record Validation and
> Callbacks says (Section 3.9):
> "If you want to be sure that an association is present, you’ll need to
> test whether the foreign key used to map the association is present,
> and not the associated object itself."
>
> Maybe the guide needs to be updated.

Yeah, I think the wording is unfortunate. Certainly you can't be sure
the association is present by checking that the FK attribute is
present.

Rather, this topic deserves a warning in my view. Something in the
line that if you check whether the FK attribute is present then you
*don't know* whether it is valid. You can decide to take the risk,
that's up to you, but the reader should be warned.

A pointer to the validates_existence plugin would be nice. Also to FK
constraints as the most robust solution, though they are kinda weird
to explain in a generic way nowadays because then #save,
#update_attributes and friends can throw exceptions for ordinary
validation errors, and that doesn't fit well with standard idioms.
This would deserve its own section in the guide with all practicals
details and gotchas.

If you'd like to have a stab at any of these revisions please give it
a go through docrails.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to