选择和预加载的Ecto查询不起作用

时间:2018-03-10 15:40:58

标签: elixir ecto

我无法弄清楚为什么我的查询无效

def query_user_public_cards (user_id) do
  User
  |> where([u], u.id == ^user_id)
  |> join(:inner, [u], _ in assoc(u, :memberships))
  |> join(:inner, [..., membership], _ in assoc(membership, :items))
  |> where([..., item], item.active == true)
  |> join(:inner, [..., item], _ in assoc(item, :cards))
  |> where([..., card], card.active == true)
  |> where([..., membership, item, card], card.language_id in [membership.teacher_lg_id, membership.student_lg_id])
  |> select([u, ...], %{user_id: u.id, email: u.email, token: u.token})
  |> preload([u, membership, item, card], [memberships: {membership, items: {item, cards: card}}])
end

Ecto查询看起来很好:

#Ecto.Query<from u in Everlearn.Members.User, join: m in assoc(u, :memberships),
join: i in assoc(m, :items), join: c in assoc(i, :cards), where: u.id == ^1,
where: i.active == true, where: c.active == true,
where: c.language_id in [m.teacher_lg_id, m.student_lg_id],
select: %{user_id: u.id, email: u.email, token: u.token},
preload: [memberships: {m, [items: {i, [cards: c]}]}]>

但我一直收到这个错误:

(Ecto.QueryError) the binding used in `from` must be selected in `select` when using `preload` in query:

有什么想法吗?

0 个答案:

没有答案