Preload Support?
Closed this issue · 2 comments
kevinastone commented
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]
drewolson commented
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)
kevinastone commented
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)