drewolson/scrivener_ecto

Paginate join incorrect

valehelle opened this issue · 0 comments

Hi everyone,
I have 2 models Post and Comments.
What I wanted to do is fetch all post and order by the latest comment.
I created this query
from(
p in Post,
join: c in assoc(p, :comments),
where: p.group_id == ^group_id,
order_by: [desc: c.inserted_at],
preload: [comments: c],
)

When I use Repo.all everything works fine.
However when I use Repo.paginate, the result is weird. On page 1 I have 3 result, on page 2 I have 1 result and so on. I set the page size to be 20 and my post only have 16 record. So it should only be 1 page.
Anyone encounter this same issue before?