On Jun 24, 2011, at 2:42 PM, John Merlino wrote:

Hey all,

Out of curiousity, all in Rails grabs all the records and converts
them into an array. Map then iterates through the returned array,
returning a new array. So why even use map here? And then the array
gets passed as local variable bt. And we instantiate object and assign
the bt array as a value of a hash of book_type. I dont see why map is
needed here.


book_details = BookType.all.map do |bt|
 Student.new(:book_type => bt)
end

Thanks for response.

In Rails 3, a lot of the query stuff is lazy-loaded, so you may not actually be getting the query you think here. Try it out in rails console, or just look at your development log to see the actual SQL that's being generated. Arel waits until the last possible second before actually issuing a query, so it may be digging out only the records you need, rather than getting all of them and winnowing down.

Walter


--
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-talk@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