Ruby on Rails: one-to-one mapping. Just semantics or really a different structure.

Posted by Sam on Stack Overflow See other posts from Stack Overflow or by Sam
Published on 2010-03-14T05:53:05Z Indexed on 2010/03/14 5:55 UTC
Read the original article Hit count: 228

Filed under:
|
|

So I'm creating a plugin for Ruby on Rails to make implemented addresses including country, state, city, and zip_code for countries that can follow that paradigm a lot easier but that's beside the point expect for how the address model is associated.

So starting with my address model.

class Address < ActiveRecord::Base
    has_one :country
    has_one :state
    has_one :city
    has_one :zip_code
end

What's the difference between saying belongs_to and has_one

Seems to be the same thing because both only require one model to declare ownership and foreign_key

And it also seems that both are logical to say.

an address belongs to an account and an account has one address

Is this only semantics or is there are real difference

© Stack Overflow or respective owner

Related posts about ruby

Related posts about on