diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 114e327926ccee9b22aa45b8b3dae377d821cad9..02114fd4d6d8e7764f5849e6f0d0238b1a4bc0f1 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1268,6 +1268,17 @@ def has_many(name, scope = nil, options = {}, &extension) # * Account#create_beneficiary (similar to b = Beneficiary.new("account_id" => id); b.save; b) # * Account#create_beneficiary! (similar to b = Beneficiary.new("account_id" => id); b.save!; b) # + # === Scopes + # + # You can pass a second argument +scope+ as a callable (i.e. proc or + # lambda) to retrieve a specific record or customize the generated query + # when you access the associated object. + # + # Scope examples: + # has_one :auther, -> { where(comment_id: 1) } + # has_one :employer, -> { joins(:company) } + # has_one :dob, ->(dob) { where("Date.new(2000, 01, 01) > ?", dob) } + # # === Options # # The declaration can also include an +options+ hash to specialize the behavior of the association.