Skip to content

Conversation

@zacksiri
Copy link
Contributor

When using use_parent_field_for_type option in polymorphic_embeds_one,
the action_and_struct/4 function's cond block was missing a clause to
handle the case when both type_from_parent_field and type_from_map
are present and match.

The existing cond only handled:

  1. type_from_parent_field is nil -> :type_not_found
  2. type_from_map is nil -> get module and return action/struct
  3. types don't match -> raise error

This caused a CondClauseError when form params included the __type__
field matching the parent field type (e.g., during form validation).

Added a true clause to handle the matching types case, which behaves
the same as when type_from_map is nil - it uses the parent field type
to determine the module and returns the appropriate action/struct tuple.

types

When using `use_parent_field_for_type` option in `polymorphic_embeds_one`,
the `action_and_struct/4` function's cond block was missing a clause to
handle the case when both `type_from_parent_field` and `type_from_map`
are present and match.

The existing cond only handled:
1. type_from_parent_field is nil -> :type_not_found
2. type_from_map is nil -> get module and return action/struct
3. types don't match -> raise error

This caused a CondClauseError when form params included the `__type__`
field matching the parent field type (e.g., during form validation).

Added a `true` clause to handle the matching types case, which behaves
the same as when type_from_map is nil - it uses the parent field type
to determine the module and returns the appropriate action/struct tuple.
@mathieuprog mathieuprog merged commit 662b312 into mathieuprog:master Dec 21, 2025
1 of 8 checks passed
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

Successfully merging this pull request may close these issues.

2 participants