Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Advice] Using this library with insert_all #84

Open
coladarci opened this issue May 23, 2023 · 1 comment
Open

[Advice] Using this library with insert_all #84

coladarci opened this issue May 23, 2023 · 1 comment

Comments

@coladarci
Copy link

Currently, from what I can tell, this library requires a changeset for all inserts.

We have a use case where we need to create 10s of thousands of records using insert_all that makes use of a polymorphic_embeds field.

We are using insert_all for performance reasons as looping through and making 10k inserts is an issue.

This results in the following error

        | ** (RuntimeError) polymorphic_embed is not able to add an autogenerated key without casting through cast_polymorphic_embed/3
        |     (polymorphic_embed 2.0.1) lib/polymorphic_embed.ex:282: PolymorphicEmbed.dump/3
        |     (ecto 3.9.2) lib/ecto/type.ex:941: Ecto.Type.process_dumpers/3
        |     (ecto 3.9.2) lib/ecto/repo/schema.ex:1006: Ecto.Repo.Schema.dump_field!/6

When using embeds_many, the same problem can exist BUT if you pass in a struct with all the necessary fields, the insert succeeds - this is discussed here: https://elixirforum.com/t/using-repo-insert-all-when-your-schema-has-embeds-many/14219

Is there a way to force a known json blob into the field when using insert_all?

Many thanks!

@pedro-laviano-peek
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants