How can I force Rails to load all models?

后端 未结 2 1813
悲哀的现实
悲哀的现实 2021-01-04 02:26

Rails does model loading on demand. For a rake task that I\'m writing, I need to be able to iterate over all ActiveRecord::Base instances (which is possible wi

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-04 02:39

    I needed all models loaded for a rake task that checks the validity of all records, and found the handy method eager_load, which can be used simply like so:

    Rails.application.eager_load!

提交回复
热议问题