I'm trying to create an association between two models:
class Person
include DataMapper::Resource
property :id, Serial
property :name, String
end
class Country
include DataMapper::Resource
property :id, Serial
property :name, String
end
I just need a simple relationship on Person (a country_id
).
My first idea was to put a has 1
property on Person:
class Person
include DataMapper::Resource
property :id, Serial
property :name, String
has 1, :country
end
Instead of a country_id
on Person table, Datamapper created a person_id
on Country.
To get what I need, I had to make it inverse:
class Country
include DataMapper::Resource
property :id, Serial
property :name, String
has 1, :person
end
This way I got my country_id
field on Person table, but it really doesn't make any sense for me.
Am I misunderstanding something or is there another way to make this association?