2017-02-09 73 views

回答

0

我做這樣的事情在我的應用程序

def Foo do 
    schema "foos" do 
    field :name, :string 

    has_many :bars_foos 
    end 
end 

def Bar do 
    schema "bars" do 
    field :other, :integer 

    has_many :bars_foos 
    end 
end 

def BarFoo do 
    schema "bars_foos" do 
    field :size, :integer 

    belongs_to :bars 
    belongs_to :foos 
    end 
end 

這使用has_manybelongs_to而不是many_to_many下列操作之一,但它實現了非常類似的東西。如果您需要直接鏈接到其他數據集,則還可以使用和through

+0

感謝您的建議。我也會用這種方法! –