aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorTom Kadwill <tomkadwill@gmail.com>2014-08-20 07:58:59 +0100
committerTom Kadwill <tomkadwill@gmail.com>2014-08-20 18:48:54 +0100
commitb64cfac9318b09cb6acbc31bdfd309d2e28f86d0 (patch)
treeb28dac442c7d9d7023f075cc14a8dff16ef19373 /activerecord
parent24a9bc4fc8d0885c64e27a62fb2703416c6ab95d (diff)
downloadrails-b64cfac9318b09cb6acbc31bdfd309d2e28f86d0.tar.gz
rails-b64cfac9318b09cb6acbc31bdfd309d2e28f86d0.tar.bz2
rails-b64cfac9318b09cb6acbc31bdfd309d2e28f86d0.zip
[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