When embeds were introduced it was never considered that an association could be inside an embed. Because of this, it silently fails.
There are couple places where changes are needed:
surface_changes function in https://github.com/elixir-ecto/ecto/blob/master/lib/ecto/repo/schema.ex#L491-L528While it makes little sense to use associations inside embeds in SQL databases, the main use case would be in various NoSQL ones, where this seems like a completely reasonable thing to do.
I would also add that embeds should also work inside an embed.
I think this type of recursion shouldn't be limited by Ecto because each design is not right or wrong it always depends on how it will be used at max show a warning if the recursion is really going deep
Embeds inside embeds should work correctly. This is a use case that is extensively tested.
Looks likes it worked in version 1.0.0, because i'm have this pattern in my app & its tests. After upgrade to 2.0 this pattern is failed.
Example app which uses same pattern & fails on PG:
https://github.com/merqlove/some_ecto/blob/master/test/some_ecto_test.exs
Error is because embed structs don't have __meta__.
It was in 1.0:
https://github.com/elixir-ecto/ecto/blob/v1.0.0/lib/ecto/schema.ex#L319
But not in 2.0:
https://github.com/elixir-ecto/ecto/blob/v2.0/lib/ecto/schema.ex#L337
Aha, i found workaround for embeds :)
Repo.preload(pts, :party, prefix: nil)
I am closing this for now. If someone is interested on this feature, a pull request is welcome!
+1 for associations inside embeds.
Most helpful comment
Aha, i found workaround for embeds :)
Repo.preload(pts, :party, prefix: nil)