Elixir Ecto:在多对多关系中使用数据透视属性
Elixir Ecto: Using a Pivot Attribute in a Many To Many Relationship
我目前在弄清楚如何在 Ecto 多对多关系中使用枢轴属性时遇到问题。
我发现了以下问题,但不幸的是没有人回答:
基本上我需要与问题中提到的相同的设置。两个模型,我需要将数据存储到数据透视条目。
有人解决这个问题吗?
提前致谢!
我正在我的一个应用程序中执行类似以下操作
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
和 belongs_to
而不是 many_to_many
,但它完成的事情非常相似。如果您需要直接 link 到其他数据集,您仍然可以将 many_to_many
与 through
一起使用。
我目前在弄清楚如何在 Ecto 多对多关系中使用枢轴属性时遇到问题。
我发现了以下问题,但不幸的是没有人回答:
基本上我需要与问题中提到的相同的设置。两个模型,我需要将数据存储到数据透视条目。
有人解决这个问题吗?
提前致谢!
我正在我的一个应用程序中执行类似以下操作
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
和 belongs_to
而不是 many_to_many
,但它完成的事情非常相似。如果您需要直接 link 到其他数据集,您仍然可以将 many_to_many
与 through
一起使用。