Skip to content

Commit

Permalink
Use ActiveRecord lazy load hooks (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
jturkel authored Apr 10, 2024
1 parent 72da3e0 commit 8586648
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 5.2.2
- Fix [issue 140](https://github.com/salsify/goldiloader/issues/140) - Defer referencing ActiveRecord classes until
it's been initialized to ensure the `Rails.application.config.filter_parameters` setting is applied properly.
**Thanks [GuillouuH](https://github.com/GuillouuH)**

## 5.2.1
- Auto include associations when the through association has already been loaded. See
[138](https://github.com/salsify/goldiloader/pull/138) for details.
Expand Down
8 changes: 6 additions & 2 deletions lib/goldiloader.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# frozen_string_literal: true

require 'active_support/all'
require 'active_record'
require 'goldiloader/compatibility'
require 'goldiloader/custom_preloads'
require 'goldiloader/auto_include_context'
require 'goldiloader/scope_info'
require 'goldiloader/association_options'
require 'goldiloader/association_loader'
require 'goldiloader/active_record_patches'

ActiveSupport.on_load(:active_record) do
# Defer referencing ActiveRecord class until it's loaded
# See https://github.com/rails/rails/issues/48704
require 'goldiloader/active_record_patches'
end

module Goldiloader
class << self
Expand Down
2 changes: 2 additions & 0 deletions lib/goldiloader/active_record_patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,5 @@ def exists?(*args)
end
::ActiveRecord::Associations::CollectionProxy.prepend(::Goldiloader::CollectionProxyPatch)
end

Goldiloader::AssociationOptions.register
2 changes: 0 additions & 2 deletions lib/goldiloader/association_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@ def register
end
end
end

Goldiloader::AssociationOptions.register
2 changes: 0 additions & 2 deletions lib/goldiloader/compatibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

module Goldiloader
module Compatibility
ACTIVE_RECORD_VERSION = ::Gem::Version.new(::ActiveRecord::VERSION::STRING).release

def self.pre_rails_7?
::ActiveRecord::VERSION::MAJOR < 7
end
Expand Down
2 changes: 1 addition & 1 deletion lib/goldiloader/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Goldiloader
VERSION = '5.2.1'
VERSION = '5.2.2'
end

0 comments on commit 8586648

Please sign in to comment.