Commit 4bd4300
Defer loading of ActiveRecord to avoid config issues
If FriendlyId references `ActiveRecord::Base` while it is loading as
part of a Rails application, it triggers the `on_load` event for
ActiveRecord, which as part of the loading process sets the current
configuration values of ActiveRecord. If any initializers try to
influence that configuration (e.g. changing defaults in
`new_framework_defaults.rb` for an app that's been upgraded), these
changes will have no effect because the configuration has already been
set in place.
To avoid this, we need to avoid triggering the `on_load` event by
wrapping the reference to `ActiveRecord::Base` in an initializer
block. The simplest way of doing this is with a `Railtie`, which will
be automatically loaded if FriendlyId is required as part of Rails.
Fixes #8231 parent a29e7d7 commit 4bd4300
File tree
4 files changed
+17
-2
lines changed- lib
- friendly_id
- test
4 files changed
+17
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
| |||
59 | 58 | | |
60 | 59 | | |
61 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
62 | 65 | | |
63 | 66 | | |
64 | 67 | | |
65 | 68 | | |
66 | 69 | | |
67 | 70 | | |
68 | 71 | | |
69 | | - | |
| 72 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
0 commit comments