Hey guys,
I’m getting stuck writing a query with some joins (maybe it’s a newbie doubt, but i can’t figure it out)
I’m trying to do a query like that:
query =
Post
|> where([p], p.private == false)
|> join(:left_lateral, [p], u in ^upvotes_count(p.id))
|> join(:left_lateral, [p, _u], d in ^downvotes_count(p.id))
|> join(:left_lateral, [p, _u, _d], c in ^comments_count(p.id))
|> join(:left_lateral, [p], v in ^total_votes_count(p.id))
|> preload([:user])
|> select([p, u, d, c, v], %{
p
| downvotes_count: d.count,
upvotes_count: u.count,
comments_count: c.count,
total_votes: v.count
})
posts = Repo.all(query)
But for some reason i get the following error:
** (CompileError) undefined function p/0
(stdlib) lists.erl:1338: :lists.foreach/2
(stdlib) erl_eval.erl:680: :erl_eval.do_apply/6
What i missing here?
I read some documents, but i can’t fix it