>
> You've uncovered Active Record's terrible secret, files isn't actually
> an Array.
>

Actually I'd call it magic or voodoo, but not a dirty secret.

It's actually a brilliant/necessary part of the arel features in Rails 3.
 When you select a recordset using Rails 3 arel features (where, order,
etc), it doesn't actually call the DB until you iterate over the resultset.
 This means if that part of the view is cached, it won't actually hit your
DB at all.  If files was an array it would have had to call the DB to fill
the array, only for it not to be used.

So, the OP's code snippet is not surprising - @product.files is not an
array, but if you use the eql? method on that object it will compare it's
internal data to an empty array (but arrays know nothing about this
ActiveRecord class).

Cheers,


Andy

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to