我正在尝试为电子邮件解决方案设计一个模式,这样我就可以使用DataMapper访问User对象上的传入和已发送消息。“收件箱”和“已发送”这两个关联并不能达到预期的效果。我做错了什么?提前感谢!
到目前为止,我有以下内容(在阅读了一些内容并复制了DM网站上的朋友示例后) --
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发布于 2012-01-23 03:16:42
我在回答我自己的问题--希望它能帮助某些人
下面的更改解决了我一直遇到的问题--
class User
...
has n, :inbox, 'Message', :child_key=>[:target_id]
has n, :sent, 'Message', :child_key=>[:source_id]
end其他的都是一样的.
https://stackoverflow.com/questions/8958727
复制相似问题