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)
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
When chaining preload/3 with nested joined assocs then only the last call will be used in the query.
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
Definitely a bug, thank you!
Most helpful comment
Definitely a bug, thank you!