Skip to content

[Advice] Using this library with insert_allΒ #84

@coladarci

Description

@coladarci

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions