Ecto: chaining preload nested joined assocs is overwriting previous calls

Created on 12 Dec 2018  路  1Comment  路  Source: elixir-ecto/ecto

Environment

  • Elixir version (elixir -v):
Erlang/OTP 21 [erts-10.1.1] [source] [64-bit] [smp:20:20] [ds:20:20:10] [async-threads:1] [hipe] [dtrace]

Elixir 1.7.4 (compiled with Erlang/OTP 21)
  • Database and version (PostgreSQL 9.4, MongoDB 3.2, etc.): PostgreSQL 11
  • Ecto version (mix deps): 3.0.5
  • Database adapter and version (mix deps): 0.14.1
  • Operating system: macOS 10.14.1
post =
  from(p in Post, as: :post, where: p.id == ^post_id)
  |> join(:inner, [post: p], u in assoc(p, :user), as: :user)
  |> join(:inner, [user: u], c in assoc(u, :country), as: :country)
  |> join(:inner, [user: u], l in assoc(u, :language), as: :language)
  |> preload([user: u, country: c], user: {u, country: c})
  |> preload([user: u, language: l], user: {u, language: l})
  |> Repo.one!()

# this will succeed because it was last call
assert %Language{} = post.user.language
# this assert will fail
assert %Country{} = post.user.country

Current behavior

When chaining preload/3 with nested joined assocs then only the last call will be used in the query.

Expected behavior

Expecting the calls to deep merge the preloads that is consistent with preloads without joins.

I have created a demo project for this issue, the failing test is here:
https://github.com/hypno2000/blog/blob/master/test/blog_test.exs#L66

Bug

Most helpful comment

Definitely a bug, thank you!

>All comments

Definitely a bug, thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jonasschmidt picture jonasschmidt  路  4Comments

tverlaan picture tverlaan  路  3Comments

atsheehan picture atsheehan  路  4Comments

jbence picture jbence  路  3Comments

AndresOsinski picture AndresOsinski  路  5Comments