diff options
author | Tom Kadwill <tomkadwill@gmail.com> | 2014-08-21 17:51:47 +0100 |
---|---|---|
committer | Tom Kadwill <tomkadwill@gmail.com> | 2014-08-21 17:51:47 +0100 |
commit | af3b2c4addb275e4829df225d7015decfa14a4e6 (patch) | |
tree | ab8a5a0d9d84df672bf0a0a6dc5803f55ae66ad7 | |
parent | f60348069afc479f84c31aebfc4bceb20a751e52 (diff) | |
download | rails-af3b2c4addb275e4829df225d7015decfa14a4e6.tar.gz rails-af3b2c4addb275e4829df225d7015decfa14a4e6.tar.bz2 rails-af3b2c4addb275e4829df225d7015decfa14a4e6.zip |
[ci skip] Added documentation for has_one scope parameter
-rw-r--r-- | activerecord/lib/active_record/associations.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 114e327926..02114fd4d6 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1268,6 +1268,17 @@ module ActiveRecord # * <tt>Account#create_beneficiary</tt> (similar to <tt>b = Beneficiary.new("account_id" => id); b.save; b</tt>) # * <tt>Account#create_beneficiary!</tt> (similar to <tt>b = Beneficiary.new("account_id" => id); b.save!; b</tt>) # + # === 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. |