drewolson / scrivener

Pagination for the Elixir ecosystem

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Preload Support?

kevinastone opened this issue · comments

What's the best way to use this with a preloaded association?

Something like?

page = from c in Comment, order_by: c.published_at |> Repo.paginate(params)
Repo.all from p in Post, preload: [comments: ^page.entries]

Are you trying to page over comments with the post preloaded or page over posts with the comments preloaded? In either case, this is already supported.

query1 = from c in Comment, order_by: c.published_at, preload: [:post]

Repo.paginate(query1)

query2 = from p in Post, preload: [:comments]

Repo.paginate(query2)

I was trying to load a Post, and then paginate the first page of comments. Ended up just using separate queries:

post = Post |> Repo.get(id)
page = from(c in Comment, where: c.post_id == ^post.id) |> Repo.paginate(conn.query_params)