# Rails3 ActiveRecord lazy loading?

**URL:** <https://discuss.rubyonrails.org/t/rails3-activerecord-lazy-loading/55283>\
**Category:** rubyonrails-talk\
**Created:** [October 23, 2010, 12:27am UTC](https://discuss.rubyonrails.org/t/rails3-activerecord-lazy-loading/55283 "2010-10-23T00:27:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marchmatch](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@marchmatch](https://discuss.rubyonrails.org/u/marchmatch)\
**Post date:** [October 23, 2010, 12:27am UTC](https://discuss.rubyonrails.org/t/rails3-activerecord-lazy-loading/55283/1 "2010-10-23T00:27:05Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [October 23, 2010, 2:34pm UTC](https://discuss.rubyonrails.org/t/rails3-activerecord-lazy-loading/55283/2 "2010-10-23T14:34:13Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![marchmatch](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@marchmatch](https://discuss.rubyonrails.org/u/marchmatch)\
**Post date:** [October 23, 2010, 3:35pm UTC](https://discuss.rubyonrails.org/t/rails3-activerecord-lazy-loading/55283/3 "2010-10-23T15:35:05Z")

</div>

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