Skip to content

Instantly share code, notes, and snippets.

@jjn1056
Created October 23, 2018 22:58
Show Gist options
  • Select an option

  • Save jjn1056/36507e4af688953fe23eb202d86ffedc to your computer and use it in GitHub Desktop.

Select an option

Save jjn1056/36507e4af688953fe23eb202d86ffedc to your computer and use it in GitHub Desktop.
sub latest_posts ($self) {
$self->Q->published_posts
->include_author
->latest(10)
->hashes->all;
}
same as ???
select
post.*,
json_agg(comments),
json_agg(author)
from posts post
left join comments on comments.post_id = post.id
join users author on author.username = post.author_username
where post.is_published is true
group by post.id, author.id
order by post.published_at DESC
limit 10;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment