数据映射器关联-什么代码? [英] Data Mapper Associations - what code?

查看:68
本文介绍了数据映射器关联-什么代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ive浏览了DataMapper文档,但正在努力查看如何执行此操作。我有两个表,我只是希望将User表的'handle'属性添加为Peeps表的一列-如下所示?

ive looked through the DataMapper docs but am struggling to see how to do this. I have two tables and I simply wish to add the 'handle' attribute from the User table, as a column to the Peeps table - as per below?

推荐答案

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

Doc: http://datamapper.org/docs/associations.html Customizing Associations section.

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

这篇关于数据映射器关联-什么代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆