首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DataMapper关联

DataMapper关联
EN

Stack Overflow用户
提问于 2012-01-22 11:31:24
回答 1查看 261关注 0票数 0

我正在尝试为电子邮件解决方案设计一个模式,这样我就可以使用DataMapper访问User对象上的传入和已发送消息。“收件箱”和“已发送”这两个关联并不能达到预期的效果。我做错了什么?提前感谢!

到目前为止,我有以下内容(在阅读了一些内容并复制了DM网站上的朋友示例后) --

代码语言:javascript
复制
class User
    include DataMapper::Resource
    property :id, Serial
    property :name, String, :required=>true
    property :email, String, :required=>true, :unique=>true
    property :password, String, :required=>true

    has n, :messages, :child_key=>[:source_id, :target_id]
    has n, :inbox, 'Message', :through=>:messages, :via=>:target
    has n, :sent, 'Message', :through=>:messages, :via=>:source
end

class Message
    include DataMapper::Resource
    property :id, Serial
    property :subject, String, :required=>true
    property :body, String

    belongs_to :source, 'User', :key=>true
    belongs_to :target, 'User', :key=>true
end
EN

回答 1

Stack Overflow用户

发布于 2012-01-23 03:16:42

我在回答我自己的问题--希望它能帮助某些人

下面的更改解决了我一直遇到的问题--

代码语言:javascript
复制
class User
    ...

    has n, :inbox, 'Message', :child_key=>[:target_id]
    has n, :sent, 'Message', :child_key=>[:source_id]
end

其他的都是一样的.

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8958727

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档