aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZachary Scott <e@zzak.io>2014-08-19 14:02:30 -0700
committerZachary Scott <e@zzak.io>2014-08-19 14:02:30 -0700
commit6b66ec3e65cf294b10f037fccc5da8175da9e8dc (patch)
tree10542afa5157e56a24321ade65df7bd32b38c8d5
parent299c2645525d4f82e72a3abdbef6b20decf04fee (diff)
parent58557179f8b957f2e140e363c482082a37220ad1 (diff)
downloadrails-6b66ec3e65cf294b10f037fccc5da8175da9e8dc.tar.gz
rails-6b66ec3e65cf294b10f037fccc5da8175da9e8dc.tar.bz2
rails-6b66ec3e65cf294b10f037fccc5da8175da9e8dc.zip
Merge pull request #16475 from tomkadwill/has_many_scope_documentation
[ci skip] Added documentation for belongs_to scope parameter
-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 d3b9b8251a..945f22d3c8 100644
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1366,6 +1366,17 @@ module ActiveRecord
# * <tt>Post#create_author!</tt> (similar to <tt>post.author = Author.new; post.author.save!; post.author</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 record or customize the generated query
+ # when you access the associated object.
+ #
+ # Scope examples:
+ # belongs_to :user, -> { where(id: 2) }
+ # belongs_to :user, -> { joins(:friends) }
+ # belongs_to :level, ->(level) { where("game_level > ?", level.current) }
+ #
# === Options
#
# [:class_name]