2017-02-09 3 views
0

현재 Ecto 다 대다 관계에서 피벗 특성을 사용하는 방법을 파악하는 데 문제가 있습니다. Elixir Ecto : 다 대다 관계에서 피벗 특성 사용

나는 다음과 같은 질문을 찾았지만 불행하게도 아무도 대답이 없었다 : 질문에서 언급 한 바와 같이

https://stackoverflow.com/questions/37158184/elixir-ecto-pivot-many-to-many-table-attributes은 기본적으로 내가 같은 설정이 필요합니다. 두 모델과 나는 피벗 항목에 데이터를 저장해야합니다.

누구에게이 문제가 해결 되었습니까?

미리 감사드립니다.

답변

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_many 대신 many_to_manybelongs_to 사용 중 하나에 다음과 같은 일을하고 있지만, 매우 비슷한을 수행합니다. 다른 데이터 세트에 대한 직접 링크가 필요한 경우에도 many_to_manythrough과 함께 사용할 수 있습니다.

+0

귀하의 제안에 감사드립니다. 나는이 접근법을 사용할 것이다! –