On Jun 18, 2014, at 12:36 PM, Ronald Fischer <li...@ruby-forum.com> wrote:

>> Since it is so important to how AR works, I think this facet of AR
>> should be documented better in the AR guide (specifically, that the AR
>> methods return ActiveRelation objects which don't actually fetch
>> anything until you want to look at them). It's a brilliant
>> implementation pattern, but counter-intuitive to newbies.
> 
> It's just "lazy evaluation" at work, and as such not so much 
> "counter-intuitive". It's only that it is not obvious that the design 
> choice was done in this way...



Perhaps "counter-intuitive" is the wrong word choice. It is something many 
people new to the framework get tripped up on. I think this is due to the fact 
that in console, if you type Person.with_blue_eyes (assuming with_blue_eyes is 
a scope), they see the SQL execute and the result immediately. 

if you type Person.with_blue_eyes; puts "x"; you don't see the SQL execute (in 
fact, it doesn't). It's the fact that console calls inspect on the last thing 
typed that makes it counter-intutive to newbies.

And of course, you have to know what lazy evaluation is and why AR does it, 
which is the secret sauce, also not something newbies can grok easily. 

I guess all I really want is for the AR guide to have a section that discusses 
this nuance (it doesn't) as I find this is something that is easy to trip up on 
and something I find myself explaining to people who are new to Rails all the 
time.

-Jason

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-talk+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/4F412A73-D823-4E1D-AD4D-F4E29FC28284%40datatravels.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to