Lazy loading in Rails 3.2.6

前端 未结 3 1670
遥遥无期
遥遥无期 2021-02-07 07:13

I have found in several resources online than when doing stuff like:

cars = Car.where(:colour => \'black\')

The query is not executed, until

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-07 07:42

    This is an interesting question....The answer is that when executing something in IRB/console, it calls inspect on the resulting object and then prints it out. If you did something like:

    User.where(:first_name => "John").class
    

    you should get back an ActiveRecord::Relation object.

    So the lazy loading for Rails still holds, it's just the way the console works.

    Hope this helps.

    Source(s): 1) https://rails.lighthouseapp.com/projects/8994/tickets/4951-rails-console-executes-where-queries-without-lazy-loading 2) Why Active Record relation is not returned in console?

提交回复
热议问题