Reputation: 1377
Does someone know, what is the limitation in Ecto that the insert all is not made to be working with changesets? Usually I need to create change sets for all entries and then map them to normal map(at the same time removing the virtual fields if existing and the not loaded entities).
Upvotes: 1
Views: 41
Reputation: 15673
The point of Changeset
is to track changes to a particular structure. Imagine if you have [change(user1, name: "Bob"), change(user2, address: "Bob Street 1")]
; What would you expect the resulting bulk insert operation to look like? The only useful thing would be basically for cs <- changesets, do: Repo.insert(cs)
which you could just do yourself. The application for insert_all
and update_all
is to do bulk insert/update of uniformly shaped data and/or from queries, which changesets are not a good fit for.
Upvotes: 1
Reputation: 2235
Repo.insert_all
can not insert into multiple tables. Since changesets can do, e.g. cast_assoc
to create/update/delete multiple associations, this conflicts with the way bulk inserts work.
Can you describe your data model, so it will be easier to talk about possible approaches to achieve what you want?
Upvotes: 1