How to test with polymorphic embedded data structure in Ex_Machina

Hiya, I want to use ex_machina to create a factory for schema that uses PolymorphicEmbed.polymorphic_embeds_one to embed an associated struct based on type. When I try to insert this into my test I get ā†’

** (RuntimeError) Elixir.PolymorphicEmbed must not be casted using Ecto.Changeset.cast/4, use Elixir.PolymorphicEmbed.cast_polymorphic_embed/2 instead.

What is the best approach to test data like this?

1 Like

@savhappy Did you find a solution here? Iā€™m running into the same problem.

Check out this github thread

It normally does not support it but the comment above mine shows that somebody decided to write a PR for it.

Though it has to be said that writing your own fixtures and combining them f.ex. with Faker is pretty easy as well.