Skip to content

Instantly share code, notes, and snippets.

@mrbrdo
Created November 7, 2014 11:13
Show Gist options
  • Save mrbrdo/58afe9da5a318d10ef75 to your computer and use it in GitHub Desktop.
Save mrbrdo/58afe9da5a318d10ef75 to your computer and use it in GitHub Desktop.
BlogsDatasource.new(Blog.all)
.select(:id, posts: { scope: Post.all, select: [:id, :author_name] }).results
# (0.1ms) SELECT blogs.id FROM "blogs"
# (0.2ms) SELECT posts.id, posts.blog_id, (posts.author_first_name || ' ' || posts.author_last_name) as author_name FROM "posts" WHERE (posts.blog_id IN (1))
PostsDatasource.new(Post.all)
.select(:id, :title, :author, :author_name).results
# (0.1ms) SELECT posts.id, posts.title, posts.author_first_name, posts.author_last_name, (posts.author_first_name || ' ' || posts.author_last_name) as author_name FROM "posts"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment