Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add example for ActiveRecord::Base.joins using a string as argument

  • Loading branch information...
commit 7c663f507f5b4f1f443949c92dbc375d42dbd6b8 1 parent cf5e0f4
@mdesantis mdesantis authored
Showing with 5 additions and 0 deletions.
  1. +5 −0 activerecord/lib/active_record/relation/query_methods.rb
View
5 activerecord/lib/active_record/relation/query_methods.rb
@@ -305,6 +305,11 @@ def reorder!(*args) # :nodoc:
#
# 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
def joins(*args)
args.compact.blank? ? self : spawn.joins!(*args.flatten)
end
Please sign in to comment.
Something went wrong with that request. Please try again.