ruby on rails - Where does ActiveRecord::Associations::CollectionProxy get the .each instance method? -


let's have models topics , posts, topic has_many :posts , post belongs_to :topic. have stuff in database @ point.

if go rails console , type

topic.find(1).posts 

i believe collectionproxy object.

=> #<activerecord::associations::collectionproxy [#<post id:30, ......>]> 

i can call .each on enumerator object.

=> #<enumerator: [#<post id: 30, ......>]:each> 

i'm confused how collectionproxy handling .each. realize it's inherited @ point i've been reading api docs , don't make clear collectionproxy inheriting unless i'm missing obvious.

this page doesn't seem tell me much, , neither this page.

activerecord::associations::collectionproxy is inherited relation, , relation forwards each , many other methods to_a.

from activerecord/lib/active_record/relation/delegation.rb#l45

delegate :to_xml, :to_yaml, :length, :collect, :map, :each, :all?, :include?, :to_ary, :join, to: :to_a

see understanding ruby , rails: delegate excellent explanation on how delegate works.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -