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

Fix casting embedded schema with no fields and type on parent #114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alisinabh
Copy link

Hey,
Firstly thank you for the great library.

Right now when casting an embedded schema that has no fields with type on parent schema, the casting ignores an empty map.

With this fix, an empty map will also be casted.

@alisinabh
Copy link
Author

Ping :)
cc: @mathieuprog @whatyouhide

@@ -185,9 +185,6 @@ defmodule PolymorphicEmbed do
{:ok, nil} when not required ->
Ecto.Changeset.put_change(changeset, field, nil)

{:ok, map} when map == %{} and not array? ->
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason this clause was removed?

Copy link
Author

@alisinabh alisinabh Dec 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this clause not removed, when there is an empty schema (an embedded schema with no fields), the casting will not work as this clause will stop the casting early.

You can try bringing this back and see the added test fail.

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