Colin Law wrote:
[...]
> I believe rails will not stop you creating a record with an empty
> user_id.  To be pedantic this is 'does not belong to any user' rather
> than 'belongs to a non-existent user' (for a non-existent user the
> user_id would contain a non-nil value for which there is no user).  

Correct.

> In
> some applications this is a valid requirement.  If you wish to prevent
> this then include validates_presence_of as you have indicated.

Also make the field not null in the DB and add a foreign key constraint 
(the foreign_key_migrations and foreign_key_associations plugins make 
this easy).  Remember, Rails' validations are not a replacement for the 
DB's integrity checks.  Don't rely solely on Rails for this.
> 
> Colin

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" 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-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to