Lazy loading in Rails 3.2.6

前端 未结 3 1663
遥遥无期
遥遥无期 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 08:00

    The console calls inspect on the result of any expression you type so that it can display it to you. inspect is one of the things that will trigger the load of the query. If you instead do

    x = User.where(:first_name => 'John'); false
    

    then you should see no query because this time the console is calling inspect on false instead of on the Active Record relation object.

提交回复
热议问题