Skip to content
Tags

,

creating / building in a one to one relationship

November 4, 2011

in a one-to-one relationship the belongs_to is in the model that holds the id column.

suppose model a belongs to model b and model b has one model a

when you do

b = a.buid_b

b.save

the relationship is not saved. you have to do a

a.save

a = b.build_a

a.save

it does save the realtionship.

i think that is because when you build you want to call save on the model that will save the id for the relationship, otherwise it will not end up doing it.

 

if you do:

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: