数据映射器关联 - 什么代码?

时间:2016-06-19 08:44:59

标签: ruby datamapper

我查看了DataMapper文档,但我很难看到如何做到这一点。我有两个表,我只想在User表中添加'handle'属性,作为Peeps表的一列 - 如下所示?

enter image description here

1 个答案:

答案 0 :(得分:1)

文档:http://datamapper.org/docs/associations.html自定义关联部分。

class User
  ...
  has n, :peeps, 'Peep',
    :parent_key => [ :handle ],      # local to this model (User)
    :child_key  => [ :user_handle ]  # in the remote model (Peep)
end

class Peep
  ...
  belongs_to :user, 'User',
    :parent_key => [ :handle ],      # in the remote model (Peep)
    :child_key  => [ :user_handle ]  # local to this model (User)
end