I am wondering about the difference between ActiveRecord::Associations::CollectionProxy and ActiveRecord::AssociationRelation.
clas
Ok. The difference is pretty simple.
Explanation based on your example:
the association proxy in v.wheels has:
v as @owner;:has_many macro.From docs:
Association proxies in Active Record are middlemen between the @owner and the @target. The @target object is not loaded until needed.
v = Vehicle.new
v.wheels # we are not sending any methods to @target object (collection of wheels)
# => #
Which means, as soon as you call any method on the @target object (that holds collection of wheels in our case) the @target is loaded, and it becomes ActiveRecord_AssociationRelation.
v.wheels.all # sending the `all` method to @target (wheels)
# => #