Well lets say your belongs_to looks like this in your Person model:
Code:
belongs_to :residence
You access it like this:
Code:
my_person = Person.find(:first, :include => :residence)
my_person.residence.streetname
my_person.residence.housenum
That is the only way to access it by default. To access it like my_person.streetname you could always do this:
Code:
class Person < ActiveRecord::Base
...
def streetname
self.residence.streetname
end
end
And so on. In Rails 1.1, which should be out sometime soon, you can use delegations to make life easier, example:
Code:
class Person < ActiveRecord::Base
belongs_to :residence
delegate :streetname, :to => 'residence'
delegate :housenum, :to => 'residence'
end
person = Person.find(:first, :include => :residence)
person.housenum # same thing as: person.residence.housenum
person.streetname # same thing as: person.residence.streetname
But don't forget, the above only works in RAILS 1.1, which is not out yet, but should be soon. But what I posted at the top of this post should hold you over.
I <3 Rails
Bookmarks