Forum: Ruby on Rails checking foreign keys on validate

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
jeroen (Guest)
on 2005-11-16 03:33
(Received via mailing list)

I've noticed that by default AR#validate doesn't check whether a given
foreign key relationship is actually valid. So if you have a book and
you set its author_id to some number that doesn't correspond to an
Author in the authors table, then it valid? will just return true. I
guess this is a rare condition because normally the author_id would come
from a pre-populated, but I just ran into this issue in one of my unit

So I guess my question is: is their an easy way to check if the
associations exist before inserting/updating a record?

This topic is locked and can not be replied to.