Fred, That's right. If I run rails runner "User.scoped" then no query to db
at all. Thanks for the enlightening info.

On Sat, Oct 23, 2010 at 9:34 AM, Frederick Cheung <
[email protected]> wrote:

>
>
> On Oct 23, 1:27 am, marchmatch <[email protected]> wrote:
> > Hi,
> >
> > Is Rails3 ActiveRecord supposed to be lazy loading? In the following
> snippet
> > when I call scoped on User model, it does return a ActiveRecord::Relation
> > object. But at the same time the query is performed: "User Load (0.3ms)
> >  SELECT "users".* FROM "users". If I do a u.all after it, no query is
> > performed. Any thoughts?
>
> It's because you're doing this in the console: irb calls inspect on
> the result of the expression in order to display it to you, which
> triggers the load of the data.
>
> Fred
> >
> > ruby-1.9.2-p0 > u=User.scoped
> >   User Load (0.3ms)  SELECT "users".* FROM "users"
> > [#<User id: 1, name: "u1", created_at: "2010-09-08 04:08:28", updated_at:
> > "2010-09-08 04:08:28">, #<User id: 2, name: "u2", created_at: "2010-09-08
> > 04:08:34", updated_at: "2010-09-08 04:08:34">, #<User id: 3, name: "u3",
> > created_at: "2010-09-08 04:08:39", updated_at: "2010-09-08 04:08:39">]
> >
> > ruby-1.9.2-p0 > u.class
> > ActiveRecord::Relation < Object
>
> --
> 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 [email protected].
> To unsubscribe from this group, send email to
> [email protected]<rubyonrails-talk%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to