aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZachary Scott <e@zzak.io>2014-08-22 00:36:26 -0700
committerZachary Scott <e@zzak.io>2014-08-22 00:36:26 -0700
commit3202b6261ab256400666c8bafb6855c3483f022c (patch)
treef71b6b505badda558be8b1c61191649f2365d6e3
parent0697b7c750892c396847b6e9dd48a589c2f74957 (diff)
parent525cbd4c2f1257f131e38caaecf01c7674b1130a (diff)
downloadrails-3202b6261ab256400666c8bafb6855c3483f022c.tar.gz
rails-3202b6261ab256400666c8bafb6855c3483f022c.tar.bz2
rails-3202b6261ab256400666c8bafb6855c3483f022c.zip
Merge pull request #16630 from tomkadwill/added_has_and_belongs_to_many_scope_documentation
[ci skip] Added documentation for has_and_belongs_to_many scope parameter
-rw-r--r--activerecord/lib/active_record/associations.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index fb8cf1cecc..4ec1c8d545 100644
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1578,6 +1578,18 @@ module ActiveRecord
# * <tt>Developer#projects.create</tt> (similar to <tt>c = Project.new("developer_id" => id); c.save; c</tt>)
# The declaration may include an +options+ hash to specialize the behavior of the association.
#
+ # === Scopes
+ #
+ # You can pass a second argument +scope+ as a callable (i.e. proc or
+ # lambda) to retrieve a specific set of records or customize the generated
+ # query when you access the associated collection.
+ #
+ # Scope examples:
+ # has_and_belongs_to_many :projects, -> { includes :milestones, :manager }
+ # has_and_belongs_to_many :categories, ->(category) {
+ # where("default_category = ?", category.name)
+ # }
+ #
# === Options
#
# [:class_name]