joins

joins(*args)
Instance Public methods

Performs a joins on args:

User.joins(:posts)
=> SELECT "users".* FROM "users" INNER JOIN "posts" ON "posts"."user_id" = "users"."id"

You can use strings in order to customize your joins:

User.joins("LEFT JOIN bookmarks ON bookmarks.bookmarkable_type = 'Post' AND bookmarks.user_id = users.id")
=> SELECT "users".* FROM "users" LEFT JOIN bookmarks ON bookmarks.bookmarkable_type = 'Post' AND bookmarks.user_id = users.id
doc_ruby_on_rails
2015-06-20 00:00:00
Comments
Leave a Comment

Please login to continue.