Closed coladarci closed 3 years ago
For what it's worth, this is what happens when I try and use PolymorphicEmbed.get_polymorphic_type
(update), I was passing in the Struct, not the Schema for the first param. This function works and is a fine workaround for now, but question above is still valid, thanks!
What happens if you use put_change/3
?
As I don't have feedback I'm closing this for now. Do not hesitate to come back if you have time to discuss further.
We are extremely excited about this library and ran into a subtle issue for our application.
While
cast_polymorphic_embed
works perfectly for us, we have a situation where we need to create a record out of an already cast embed. I.e we want to move the value from one persisted record to another record.I tried, as a work around, to use
Map.from_struct
and then re-cast the data, but the issue here is that the Struct that is exposed doesn't have the__type__
field and our casting very much needs it as we can't infer the type since many sub-types share the same fields (don't ask :) )I'm going to go down the path of using
get_polymorphic_type/3
and re-casting, though this isn't working, either, yet for reasons I haven't yet determined.That said, I believe the correct answer to this is to implement
put_polymorphic_embed
so I can just drop in an existing value, somehow, instead of having to re-cast it. What do you think?