Closed maennchen closed 3 years ago
PS: If that PR is accepted, I'll send another one for Ecto.embeded_load/3
Looks amazing. I'll work on the library in the coming days. Busy on something else now for a little while. Get back to you soon.
@mathieuprog Any updates?
Sorry for the delay. This is an amazing PR. Can I just know what this is for?
def embed_as(_other, _params), do: :self
Commenting it out will make the tests still pass. If we can't think of any failing test, we shouldn't have this function clause I think.
@mathieuprog I seem to have copied that from somewhere. I've removed the second clause.
I would leave the pattern matching to json like you did before. More explicit.
@mathieuprog We'll have to take any atom as a parameter. I can leave two clauses that both return :dump
(one for json
, one for _
) or one clause like it is now.
(Default is :self
)
What other atom than :json
is possible to receive for this library? It will always be :json
as to my understanding. That's why all the tests pass using only :json
. Try to remove the other clause and it works.
@mathieuprog Not really. The user can call Ecto.embedded_dump
on any schema he has which includes a field using this library.
For example one could write an XML export of a schema using this functionality.
Ecto internally uses it to serialize embed JSON fields with format set to json
.
Thanks. So the last commit is correct: we should always let our custom dump
be called. Not use :self
otherwise nested polymorphic embeds won't work. Did I get this right?
I think that's correct :+1:
embed_as
is still a little obscure to me, and that's why I missed this huge improvement in the code...
You mentioned somewhere you will fix something else? load
?
@mathieuprog I'll probably do a PR for load as well. Might take some time though until I find some free time.
Simplifies Code by using functionality maintained by Ecto