diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 1c5a737696edadbbde20ecdb4535150ba647aefe..e73b855241af8bd76b1228d258d153bf30858891 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1366,6 +1366,17 @@ def has_one(name, scope = nil, options = {}) # * Post#create_author! (similar to post.author = Author.new; post.author.save!; post.author) # 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]