I'm working on an association between two models:
class Person < ActiveRecord::Base
belongs_to :user
end
class User < ActiveRecord::Base
has_one :person
end
Many person
records exist in the system that don't necessarily correspond to a user
, but when creating a user
you need to either create a new person
record or associate to an existing one.
What would be the best way to associate these two models when the person
record already exists? Do I need to manually assign the user_id
field, or is there a Rails way of doing that?