Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Eager load in a to_prepare block #61

Open
fxn opened this issue Nov 22, 2022 · 0 comments
Open

Eager load in a to_prepare block #61

fxn opened this issue Nov 22, 2022 · 0 comments

Comments

@fxn
Copy link

fxn commented Nov 22, 2022

There is an engine initializer doing this:

Rails.application.eager_load!
ContentfulModel::Base.descendents.each do |klass|
  klass.send(:add_entry_mapping)
end

Rails applications cannot load application code so early. If you change a content model and reload, nobody is invoking #add_entry_mapping on it again. In Rails 7 this is not even possible.

That should be done in a to_prepare block, so that it runs when things are ready on boot, and also on every reload.

(This logic is not related to Zeitwerk, though Rails and Zeitwerk are being polished to uncover latent issues like this one.)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant