From b64cfac9318b09cb6acbc31bdfd309d2e28f86d0 Mon Sep 17 00:00:00 2001 From: Tom Kadwill Date: Wed, 20 Aug 2014 07:58:59 +0100 Subject: [ci skip] Added documentation for has_many scope parameter --- activerecord/lib/active_record/associations.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'activerecord') 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 # * Firm#clients.create! (similar to c = Client.new("firm_id" => id); c.save!) # 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 -- cgit v1.2.3