【发布时间】:2018-09-13 21:33:45
【问题描述】:
有这个架构
many_to_many :customers, User,
join_through: Customer, on_replace: :delete
我想添加一个 on_delete 子句:
on_delete: :delete_all
所以我用
修改了架构many_to_many :customers, User,
join_through: Customer, on_replace: :delete,
on_delete: :delete_all
并创建了一个迁移,但由于它是多对多的,并且它创建了一个新表,我不知道如何引用该字段,我已经搜索了 ecto 文档,但找不到涵盖这种情况的示例:
defmodule Migration do
use Ecto.Migration
def change do
alter table(:products) do
modify :customers, references(:customers, on_delete: :delete_all)
end
end
end
但是在运行迁移时,它显然告诉我列客户不存在:
(undefined_column):关系“产品”的“客户”列不 存在
在 iex 上显示为 ecto 关联
customers: #Ecto.Association...
总结一下,基本上,我想在删除产品的时候删除客户。
【问题讨论】:
标签: elixir phoenix-framework ecto