I've got two models, that link to each other.
class User
include DataMapper::Resource
property :id, Serial
has n, :mail_addresses
end
class MailAddress
include DataMapper::Resource
property :id, Serial
property :email, String, :required => true, :unique => true, :format => :email_address
belongs_to :user
end
Now I want to add a primary mail address to a user. So it can do things like
some_user.primary_mail_address = some_user.mail_addresses.first
I've been trying to do things like this on the user model, but without any luck.
property :primary_mail_address_id, Integer, required: false
has 1, :primary_mail_address, model: 'MailAddress', parent_key: [:primary_mail_address_id], child_key: [:id]
The above trick allows me to execute the code sample, but the primary_mail_address_id won't get updated when I do that.
How to do it?