I am referring to Polymorphic associations with many to many — Ecto v3.8.4
By using
def changeset(struct, params \\ %{}) do
struct
|> Ecto.Changeset.cast(params, [:name])
|> Ecto.Changeset.cast_assoc(
:todo_items,
required: true
)
end
and
def create_todo_list(attrs \\ %{}) do
%TodoList{}
|> TodoList.changeset(attrs)
|> Repo.insert()
end
I believe Ecto will attempt to create TodoList
, TodoItems
, TodoListItems
all at once. But what i wish to achieve is to create TodoList
but only update TodoListItems
since for me TodoItems
are already created beforehand. Tried changing cast_assoc
to put_assoc
but it doesn’t quite work. How can i do this?