0
我想設計一個電子郵件解決方案的模式,以便我可以使用DataMapper訪問用戶對象上的傳入和發送的消息。 「收件箱」和「發送」的關聯不符合目的。我究竟做錯了什麼?提前致謝!DataMapper協會
我下面到目前爲止(讀位,然後複製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