Skip to content

Instantly share code, notes, and snippets.

@wycleffsean
Created February 17, 2016 15:30
Show Gist options
  • Save wycleffsean/741823ede64c1c86bbe9 to your computer and use it in GitHub Desktop.
Save wycleffsean/741823ede64c1c86bbe9 to your computer and use it in GitHub Desktop.
Arel and ActiveRecord

Join

users = User.arel_table
comments = Comment.arel_table

#select users with comments
User.join(
  users.joins(comments).on(
    users[:id].eq(comments[:user_id])
  ).join_sources
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment