mathieuprog / polymorphic_embed

Polymorphic embeds in Ecto
Apache License 2.0
341 stars 63 forks source link

feat: allow changing on_cast behavior #40

Closed duzzifelipe closed 3 years ago

duzzifelipe commented 3 years ago

Currently, when you try to normally cast a value into a polymorphic field, not using the specific cast_polymorphic_embed function, you receive a raised error.

Although, some libraries such as ex_machina casts fields directly without using a changeset. I feel this is a common behavior when you're mocking data, for example.

The idea of this PR is to let users choose if they want to raise on normal cast or just let the value be encoded "as is".

mathieuprog commented 3 years ago

Hey. I think this problem is specific to ex_machina. I don't think it's a common behavior, see here the alternative to ex_machina: https://hexdocs.pm/ecto/test-factories.html. No changeset is even used.

See here the discussion on that issue: https://github.com/mathieuprog/polymorphic_embed/pull/26

mathieuprog commented 3 years ago

Also: https://github.com/thoughtbot/ex_machina/issues/407