Having this schema
many_to_many :customers, User,
join_through: Customer, on_replace: :delete
I want to add an on_delete clause:
on_delete: :delete_all
So I modified the schema with
many_to_many :customers, User,
join_through: Customer, on_replace: :delete,
on_delete: :delete_all
And created a migration, but as it's a many to many and it creates a new table I dont know how can you reference the field, I have searched through ecto docs but couldnt find an example covering this case:
defmodule Migration do
use Ecto.Migration
def change do
alter table(:products) do
modify :customers, references(:customers, on_delete: :delete_all)
end
end
end
But when running the migration it obviously tells me the column customers doesnt exist:
(undefined_column): column "customers" of relation "products" does not exist
On iex it's shown as an ecto association
customers: #Ecto.Association...
To sum it up, basically, I want to delete the customer when the product is deleted.