From 7354d71f9201f81d5ab7f1a1cfb94d266edc8993 Mon Sep 17 00:00:00 2001 From: Gannon McGibbon Date: Fri, 8 Feb 2019 00:02:14 -0500 Subject: Clarify collection proxy docs The docs for `ActiveRecord::Associations::CollectionProxy` describe `ActiveRecord::Associations::Association`. I've moved them to association and rewrote collection proxy's docs to be more applicable to what the class actually does.` [ci skip] --- .../lib/active_record/associations/association.rb | 17 +++++++++++++++++ .../active_record/associations/collection_proxy.rb | 19 ++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb index 5d0927f17d..0bb63b97ae 100644 --- a/activerecord/lib/active_record/associations/association.rb +++ b/activerecord/lib/active_record/associations/association.rb @@ -17,6 +17,23 @@ module ActiveRecord # CollectionAssociation # HasManyAssociation + ForeignAssociation # HasManyThroughAssociation + ThroughAssociation + # + # Associations in Active Record are middlemen between the object that + # holds the association, known as the owner, and the associated + # result set, known as the target. Association metadata is available in + # reflection, which is an instance of ActiveRecord::Reflection::AssociationReflection. + # + # For example, given + # + # class Blog < ActiveRecord::Base + # has_many :posts + # end + # + # blog = Blog.first + # + # The association of blog.posts has the object +blog+ as its + # owner, the collection of its posts as target, and + # the reflection object represents a :has_many macro. class Association #:nodoc: attr_reader :owner, :target, :reflection diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index 78993cee8a..edcb44f0fc 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -2,11 +2,8 @@ module ActiveRecord module Associations - # Association proxies in Active Record are middlemen between the object that - # holds the association, known as the @owner, and the actual associated - # object, known as the @target. The kind of association any proxy is - # about is available in @reflection. That's an instance of the class - # ActiveRecord::Reflection::AssociationReflection. + # Collection proxies in Active Record are middlemen between an + # association, and its target result set. # # For example, given # @@ -16,14 +13,14 @@ module ActiveRecord # # blog = Blog.first # - # the association proxy in blog.posts has the object in +blog+ as - # @owner, the collection of its posts as @target, and - # the @reflection object represents a :has_many macro. + # The collection proxy returned by blog.posts is built from a + # :has_many association, and delegates to a collection + # of posts as the target. # - # This class delegates unknown methods to @target via - # method_missing. + # This class delegates unknown methods to the association's + # relation class via a delegate cache. # - # The @target object is not \loaded until needed. For example, + # The target result set is not loaded until needed. For example, # # blog.posts.count # -- cgit v1.2.3