[Rails] Re: does rails enforce referential integrity???
Łukasz Piestrzeniewicz
bragi.ragnarson+rf at gmail.com
Sun Aug 13 11:11:18 GMT 2006
Greg Hauptmann wrote:
> Hi,
>
> Is rails supposed to support referential integrity? That is rails
> either support to be able to ensure that when a new contact is created
> this can only happen if a valid suberb is associated with it, and which
> mechanisms of the below are supposed to do this?
> (a) using DB foreign key constraints information as a basis?
> (b) using the "has_one" line in the model file to enfore?
Skip the db constrains and use Rails validations to achive referential
integrity:
> --------------------------
> class Contact < ActiveRecord::Base
> has_one :suberb
> end
> --------------------------
> class Suberb < ActiveRecord::Base
> belongs_to :contact
validates_presence_of :contact_id
validates_associated :contact
> end
Cheers,
Bragi
--
Posted via http://www.ruby-forum.com/.
More information about the Rails
mailing list