2012-01-22 31 views
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 

回答

1

我回答我的問題 - 希望它可以幫助別人

以下更改解決我一直有這個問題 -

class User 
    ... 

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

一切,仍然是相同的......