cookpad / arproxy

Arproxy is a proxy between ActiveRecord and database adapter
https://github.com/cookpad/arproxy
MIT License
327 stars 26 forks source link

Avoid eager loading `ActiveRecord::Base` #22

Open yujideveloper opened 2 years ago

yujideveloper commented 2 years ago

Problem

When Arproxy is loaded by specifying Gemfile, require "active_record/base" is called and ActiveRecord::Base is loaded. Just when Rails.application.config.active_record.xxx are copied to ActiveRecord::Base.xxx. So, config/initializers/new_framework_defaults_x_x.rb does not work well.

This PR's solution

Arproxy avoid eager loading ActiveRecord::Base, and defer proxy_chain.enable! call until ActiveRecord::Base is loaded.

Other solution

I thought following solution, but it is a bit tricky. I think this PR's solution is easier for gem users.

# Gemfile
gem "arproxy", require: false
# config/initializers/arproxy.rb
Rails.configuration.after_initialize do # or on_prepare
  require "arproxy"

  # setup arproxy...
end
sorah commented 2 years ago

I understand the problem but I believe this can be resolved using Railtie API. Have you considered that?