aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorZachary Scott <e@zzak.io>2014-08-20 12:32:53 -0700
committerZachary Scott <e@zzak.io>2014-08-20 12:32:53 -0700
commit6ef0dd94a52a86d87165c2b64f9a434d4c786e1f (patch)
treeac218d47a4714093c6ff8c336f2a6329b9d09665 /activerecord
parent2b7d67d49df8b88ef4815199f2ce5c11f09fe06f (diff)
parentb64cfac9318b09cb6acbc31bdfd309d2e28f86d0 (diff)
downloadrails-6ef0dd94a52a86d87165c2b64f9a434d4c786e1f.tar.gz
rails-6ef0dd94a52a86d87165c2b64f9a434d4c786e1f.tar.bz2
rails-6ef0dd94a52a86d87165c2b64f9a434d4c786e1f.zip
Merge pull request #16575 from tomkadwill/added_has_many_scope_documentation
[ci skip] Added documentation for has_many scope parameter
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 945f22d3c8..114e327926 100644
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1133,6 +1133,17 @@ module ActiveRecord
# * <tt>Firm#clients.create!</tt> (similar to <tt>c = Client.new("firm_id" => id); c.save!</tt>)
# The declaration can also 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_many :comments, -> { where(author_id: 1) }
+ # has_many :employees, -> { joins(:address) }
+ # has_many :posts, ->(post) { where("max_post_length > ?", post.length) }
+ #
# === Options
# [:class_name]
# Specify the class name of the association. Use it only if that name can't be inferred