2011-03-18 77 views
0

文章有許多作者,編輯,翻譯等。 是否可以生成連接模型?或者,在這種情況下,解決方案是手動創建每個加入模型。Datamapper多對多關係

class Article 
    include DataMapper::Resource 

    property :id, Serial 

    property :published_date, Date 
    property :status, Enum[ :pending, :accepted, :declined, :modified, :new ], :default => :new 
    property :visible, Boolean, :default => false 

    timestamps :at 

    has n, :authors, 'Person', :through => Resource 
end 


class Person 

    include DataMapper::Resource 

    property :id, Serial 

    property :name, String 
    property :about, Text 
    property :gender, Enum[ :male, :female ] 
    property :birthday, Date 

    timestamps :at 

    has n, :articles, :through => Resource 
end 

回答