This post is really just a quick reminder for myself any time I need to use ActiveRecord::Associations::Preloader to customize the scope of a preload.

It’s a private API, so it changes a lot. Really need to write a gem that does this gracefully…

Rails 7.1

ActiveRecord::Associations::Preloader.
  new(
    records: companies,
    associations: :projects,
    scope: Project.where(foo: "bar"),
  ).
  call