2010-09-25 59 views
1

我想要一個用戶表。這些用戶應具有N個接觸和n的消息..使DataMapper關聯正確的方法

我的代碼是:

... 
class User 
    include DataMapper::Resource 

    property :id, Serial, :key => true 
    property :nickname, String 

    has n, :contacts 
    has n, :messages 
end 

class Contact 
    include DataMapper::Resource 

    belongs_to :user 

    property :id, Serial, :key => true 
    property :authgiven, String 

    has 1, :user  
end 

class Message 
    include DataMapper::Resource 

    belongs_to :user 

    property :id, Serial, :key => true 
    property :data, String 
end 

#apply models (validation etc.) 
DataMapper.finalize 
... 

有沒有錯誤初始化DataMapper的,但是當我嘗試創建一個新的用戶或什麼的,保存始終返回false。 ..有人可以指出什麼是錯的?

我是很新的DataMapper的,它總是爲我工作與沒有關係簡單的表,所以我相信這與我宣佈1的方式來做到:N的關係......

回答

1

嘿,你應該從聯繫人模型中刪除1::用戶行,你應該很好。

+0

那麼好吧thx我發現已經...我用一個應該存儲id的整數替換它...它會更加優雅作爲一個協會,但... – apirogov 2010-09-26 19:57:43