aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorZachary Scott <e@zzak.io>2014-08-21 10:05:04 -0700
committerZachary Scott <e@zzak.io>2014-08-21 10:05:04 -0700
commit572c03e22e7bc842548ef9cb6959c9585265f89b (patch)
tree97b5067c1964958720bf960e7be75f2e72a28f00 /activerecord
parentddb2d57223e20eae61276592e4270405fa8d87aa (diff)
parentaf3b2c4addb275e4829df225d7015decfa14a4e6 (diff)
downloadrails-572c03e22e7bc842548ef9cb6959c9585265f89b.tar.gz
rails-572c03e22e7bc842548ef9cb6959c9585265f89b.tar.bz2
rails-572c03e22e7bc842548ef9cb6959c9585265f89b.zip
Merge pull request #16617 from tomkadwill/added_has_one_scope_documentation
[ci skip] Added documentation for has_one 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 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.