2017-02-09 13 views
0

現在、Ectoの多対多の関係でピボット属性を使用する方法がわかりません。エリクサーエクト:多対多関係のピボット属性の使用

私は、次の質問を見つけましたが、残念ながら、誰も答えを持っていた:https://stackoverflow.com/questions/37158184/elixir-ecto-pivot-many-to-many-table-attributes

質問で述べたように基本的に私は、同じ設定を必要としています。 2つのモデルとピボットエントリにデータを格納する必要があります。

誰かがこの問題の解決方法を持っていますか?

ありがとうございます!

答えて

0

私は私のアプリケーションの1

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 

に次のようなものをやっているこれは、代わりにmany_to_manyhas_manybelongs_toを使用していますが、それは非常によく似た何かを達成します。他のデータセットへの直接リンクが必要な場合は、many_to_manythroughと併用することもできます。

+0

ご提案いただきありがとうございます。私もこのアプローチを使用します! –