I tried to use the insert_all
functions to batch insert 2 records, but it always fails with Enumerable not implemented for Model
:
Repo.insert_all(Model, [%Model{id: 1, friend_id: 4}, %Model{id: 4, friend_id: 1}])
I got it working by inserting every record at once:
Multi.new
|> Multi.insert(:model1, %Model{id: 1, friend_id: 4})
|> Multi.insert(:model2, %Model{id: 4, friend_id: 1})
|> Repo.transaction
Maybe my misunderstanding is that only normal maps are supported?
Repo.insert_all(Model, [%{id: 1, friend_id: 4}, %{id: 4, friend_id: 1}])
Unfortunately, then the timestamp values are not automatically set:
null value in column "inserted_at" violates not-null constraint
Is there any way to achieve the batch insertion with phoenix models and what exactly is my mistake or misunderstanding?