On Fri, Feb 4, 2011 at 9:36 PM, Michael Pavling <[email protected]> wrote:
> On 4 February 2011 20:30, Paul <[email protected]> wrote:
>> I've always thought that validating the :parent (and not the foreign
>> key) is the *more* correct thing to do
>> I've never
>> been able to get a definite answer on whether one should do,
>>
>> validates :parent, :presence => true
>
> yep - always validate the object - no sense validating a foreign key
> field, when the foreign key might not link to a row in the association
> table.

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.

Rainer

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