Type:
Class

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.

For example, given

1
2
3
4
5
class Blog < ActiveRecord::Base
  has_many :posts
end
 
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.

This class delegates unknown methods to @target via method_missing.

The @target object is not loaded until needed. For example,

1
blog.posts.count

is computed directly through SQL and does not trigger by itself the instantiation of the actual post records.

size
  • References/Ruby on Rails/Rails/Classes/ActiveRecord/ActiveRecord::Associations/ActiveRecord::Associations::CollectionProxy

size() Instance Public methods Returns the size of the collection. If the collection

2025-01-10 15:47:30
scoping
  • References/Ruby on Rails/Rails/Classes/ActiveRecord/ActiveRecord::Associations/ActiveRecord::Associations::CollectionProxy

scoping() Instance Public methods We don't want this object to be put on the

2025-01-10 15:47:30
any?
  • References/Ruby on Rails/Rails/Classes/ActiveRecord/ActiveRecord::Associations/ActiveRecord::Associations::CollectionProxy

any?(&block) Instance Public methods Returns true if the collection

2025-01-10 15:47:30
fifth
  • References/Ruby on Rails/Rails/Classes/ActiveRecord/ActiveRecord::Associations/ActiveRecord::Associations::CollectionProxy

fifth(*args) Instance Public methods Same as first except returns

2025-01-10 15:47:30
push
  • References/Ruby on Rails/Rails/Classes/ActiveRecord/ActiveRecord::Associations/ActiveRecord::Associations::CollectionProxy

push(*records) Instance Public methods Alias for:

2025-01-10 15:47:30
empty?
  • References/Ruby on Rails/Rails/Classes/ActiveRecord/ActiveRecord::Associations/ActiveRecord::Associations::CollectionProxy

empty?() Instance Public methods Returns true if the collection

2025-01-10 15:47:30
destroy
  • References/Ruby on Rails/Rails/Classes/ActiveRecord/ActiveRecord::Associations/ActiveRecord::Associations::CollectionProxy

destroy(*records) Instance Public methods Destroys the records

2025-01-10 15:47:30
loaded?
  • References/Ruby on Rails/Rails/Classes/ActiveRecord/ActiveRecord::Associations/ActiveRecord::Associations::CollectionProxy

loaded?() Instance Public methods Returns true if the association

2025-01-10 15:47:30
forty_two
  • References/Ruby on Rails/Rails/Classes/ActiveRecord/ActiveRecord::Associations/ActiveRecord::Associations::CollectionProxy

forty_two(*args) Instance Public methods Same as first except returns

2025-01-10 15:47:30
many?
  • References/Ruby on Rails/Rails/Classes/ActiveRecord/ActiveRecord::Associations/ActiveRecord::Associations::CollectionProxy

many?(&block) Instance Public methods Returns true if the collection has

2025-01-10 15:47:30