Hi I have just started learning Rails3 (ruby1.92, Rails3.0.5) and watched railscast episode 202. I tried Article.where(:hidden => true) from console. I have a confusion there since the cast says that , the above statement execute query in the view when iterated. I did not understand that. I got result from query in the console it self when executed Article.where(:hidden => true). Please comment Thanks -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi i am talking exactly about this. Now only I found this https://rails.lighthouseapp.com/projects/8994/tickets/4476-lazy-loading-broken-since-beta3 I am getting this not only in console but application also. Has anything changed in Rails3.0.5? -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Apr 7, 8:56 am, Tom Mac <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi > I have just started learning Rails3 (ruby1.92, Rails3.0.5) and watched > railscast episode 202. I tried > Article.where(:hidden => true) from console. I have a confusion there > since the cast says that , the above statement execute query in the view > when iterated. I did not understand that. I got result from query in the > console it self when executed Article.where(:hidden => true). Please > commentThe issue is that the console wants to print the result of the expression you type, which forces ActiveRecord to execute the query. Fred> > Thanks > > -- > Posted viahttp://www.ruby-forum.com/.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Fred Thanks . I tried from sample application also like def index @articles = Article.where(:hidden => true) puts @articles.inspect ------------- end Here also the query executed. I dont know why. -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Apr 7, 10:49 am, Tom Mac <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi Fred > Thanks . I tried from sample application also like > def index > @articles = Article.where(:hidden => true) > puts @articles.inspect > ------------- > end > > Here also the query executed. I dont know why.because you called inspect on @articles Fred> > -- > Posted viahttp://www.ruby-forum.com/.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Then how can I check that it is not triggering sql. I did not understand it properly. Could you explain more please? Frederick Cheung wrote in post #991438:> On Apr 7, 10:49am, Tom Mac <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Hi Fred >> Thanks . I tried from sample application also like >> def index >> @articles = Article.where(:hidden => true) >> puts @articles.inspect >> ------------- >> end >> >> Here also the query executed. I dont know why. > > because you called inspect on @articles > > Fred-- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Apr 7, 1:21 pm, Tom Mac <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi > Then how can I check that it is not triggering sql. I did not > understand it properly. Could you explain more please? >Look in your development log and ensure that you don''t touch the scope - when you do anything other than adding conditions, joins etc. to the scope you force active record to evaluate it. Fred> Frederick Cheung wrote in post #991438: > > > On Apr 7, 10:49am, Tom Mac <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> Hi Fred > >> Thanks . I tried from sample application also like > >> def index > >> @articles = Article.where(:hidden => true) > >> puts @articles.inspect > >> ------------- > >> end > > >> Here also the query executed. I dont know why. > > > because you called inspect on @articles > > > Fred > > -- > Posted viahttp://www.ruby-forum.com/.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
the difference might be illustrated by the following: Article.where(:hidden => true).to_sql vs. Article.where(:hidden => true).all.to_sql in the first, you are able to get the (currently un-executed) sql statement in the second, you will get an undefined_method error because having been evaluated, you now have an array (or a proxy to an array) instead of a scope. does that help? On Apr 7, 7:59 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 7, 1:21 pm, Tom Mac <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > > Hi > > Then how can I check that it is not triggering sql. I did not > > understand it properly. Could you explain more please? > > Look in your development log and ensure that you don''t touch the scope > - when you do anything other than adding conditions, joins etc. to the > scope you force active record to evaluate it. > > Fred > > > > > > > > > Frederick Cheung wrote in post #991438: > > > > On Apr 7, 10:49am, Tom Mac <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > >> Hi Fred > > >> Thanks . I tried from sample application also like > > >> def index > > >> @articles = Article.where(:hidden => true) > > >> puts @articles.inspect > > >> ------------- > > >> end > > > >> Here also the query executed. I dont know why. > > > > because you called inspect on @articles > > > > Fred > > > -- > > Posted viahttp://www.ruby-forum.com/.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.