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.

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

spawn() Instance Public methods Alias for:

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

destroy_all() Instance Public methods Deletes the records of the collection

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

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

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

prepend(*args) Instance Public methods

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

target() Instance Public methods

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

count(column_name = nil, options = {}) Instance Public methods Count all records

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

to_ary() Instance Public methods Returns a new array of objects from the collection

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

take(n = nil) Instance Public methods

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

delete(*records) Instance Public methods Deletes the records supplied

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

concat(*records) Instance Public methods Add one or more records to the collection

2025-01-10 15:47:30