aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJared Beck <jared@jaredbeck.com>2015-11-25 15:07:34 -0500
committerJared Beck <jared@jaredbeck.com>2015-11-25 15:17:29 -0500
commitaad6000f0b82d5113b82e40f1757d37c75d5de1c (patch)
tree5a545f2ab26a54f5b9c6bd65f785275b41db17dc /activerecord
parent3fcc0ca99107fa57110421b392f5854555f17fe2 (diff)
downloadrails-aad6000f0b82d5113b82e40f1757d37c75d5de1c.tar.gz
rails-aad6000f0b82d5113b82e40f1757d37c75d5de1c.tar.bz2
rails-aad6000f0b82d5113b82e40f1757d37c75d5de1c.zip
Docs: ActiveRecord::QueryMethods#joins
[ci skip]
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb24
1 files changed, 22 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 7a4bf5338d..dbecb842b5 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -411,10 +411,30 @@ module ActiveRecord
self
end
- # Performs a joins on +args+:
+ # Performs a joins on +args+. The given symbol(s) should match the name of
+ # the association(s).
#
# User.joins(:posts)
- # # SELECT "users".* FROM "users" INNER JOIN "posts" ON "posts"."user_id" = "users"."id"
+ # # SELECT "users".*
+ # # FROM "users"
+ # # INNER JOIN "posts" ON "posts"."user_id" = "users"."id"
+ #
+ # Multiple joins:
+ #
+ # User.joins(:posts, :account)
+ # # SELECT "users".*
+ # # FROM "users"
+ # # INNER JOIN "posts" ON "posts"."user_id" = "users"."id"
+ # # INNER JOIN "accounts" ON "accounts"."id" = "users"."account_id"
+ #
+ # Nested joins:
+ #
+ # User.joins(posts: [:comments])
+ # # SELECT "users".*
+ # # FROM "users"
+ # # INNER JOIN "posts" ON "posts"."user_id" = "users"."id"
+ # # INNER JOIN "comments" "comments_posts"
+ # # ON "comments_posts"."post_id" = "posts"."id"
#
# You can use strings in order to customize your joins:
#