Permalink
Browse files

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

  • Loading branch information...
mdesantis committed Feb 7, 2013
1 parent cf5e0f4 commit 7c663f507f5b4f1f443949c92dbc375d42dbd6b8
Showing with 5 additions and 0 deletions.
  1. +5 −0 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

0 comments on commit 7c663f5

Please sign in to comment.