Association dows not grt foreign key

I have a 1 to 1 relationship using a similar example as below
(has_one, belongs_to)

but when I do the save, the foreign key of the child object is not set
to the id of the parent object in the relation ship

any ideas?

cheers

dion


class Person < ActiveRecord::Base
has_one :address
validates_presence_of :email

end
class Address < ActiveRecord::Base
belongs_to :person
end


person = Person.new

person.email = “[email protected]
address = Address.new
address.city = “Austin”
person.address = address
person.save
person2 = Person.find_by_email “[email protected]
person2.address.city
=> “Austin”

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs