Skip to content

Conversation

@atdrendel
Copy link

@atdrendel atdrendel commented Nov 20, 2024

This is an attempt to make ExMachina work with polymorphic_embed following the lead of this comment.

@westmark
Copy link

I was using a local version of the same, and after updating my packages (unsure which caused it) I had to change

&match?({:parameterized, PolymorphicEmbed, _options}, schema.__schema__(:type, &1))

to

&match?({:parameterized, {PolymorphicEmbed, _options}}, schema.__schema__(:type, &1))

for the casting to work

schema.__schema__(:fields),
&match?({:parameterized, PolymorphicEmbed, _options}, schema.__schema__(:type, &1))
)
end
Copy link

Choose a reason for hiding this comment

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

Need to account for array of polymorphic embeds:

  defp schema_polymorphic_embeds(schema) do
    Enum.filter(schema.__schema__(:fields), fn field ->
      case schema.__schema__(:type, field) do
        {:parameterized, {PolymorphicEmbed, _options}} -> true
        {:array, {:parameterized, {PolymorphicEmbed, _options}}} -> true
        _ -> false
      end
    end)
  end

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.

4 participants