Ecto: Support associations inside embeds

Created on 7 Dec 2016  路  7Comments  路  Source: elixir-ecto/ecto

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:

While 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.

Enhancement Advanced

Most helpful comment

Aha, i found workaround for embeds :)
Repo.preload(pts, :party, prefix: nil)

All 7 comments

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

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stavro picture stavro  路  4Comments

wojtekmach picture wojtekmach  路  3Comments

kelostrada picture kelostrada  路  3Comments

jbence picture jbence  路  3Comments

alaadahmed picture alaadahmed  路  4Comments