From: Daniel DeLorme Date: 2006-08-04T09:03:32+09:00 Subject: Re: Array#size empties the Array?? Sven Suska wrote: >> This may be irrelevant, but what's rks.class.ancestors? > > [Array, > ActiveSupport::CoreExtensions::Array::Conversions, > Enumerable, > Object, > Kernel] This is probably wrong. Try to do this instead: (class << rks;self;end).ancestors and you'll probably find this: [ActiveRecord::Associations::HasManyAssociation, ActiveRecord::Associations::AssociationCollection, ActiveRecord::Associations::AssociationProxy, Object, Base64::Deprecated, Base64, Kernel] ActiveRecord associations forward most messages (including 'class') to the underlying array structure, but some messages (like 'size') are part of the association class itself. I think what's happening is that by calling 'size' first, the objects have not yet been fetched from the database so instead it uses a COUNT(*) query to find the size. When calling 'length' (or any other method) first, the objects are fetched from the database and placed in an array and the 'length' message is forwarded to that array. Then, when 'size' is invoked again, it notices that the array is already present and uses its size instead of wasting time doing another DB query. Normally the results should be the same but in your case something weird is happening. I don't know what exactly but this should give you some avenues to investigate. Daniel