-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
per model config can no longer be defined before associations #3490
Comments
q3aiml
added a commit
to q3aiml/rails_admin
that referenced
this issue
Mar 10, 2022
Attempt to restore 2.x config loading behavior where 1) initializer config block evaluates immediately so that routes are configured correctly while 2) per-model config blocks only evaluate after all the models are loaded and associations are defined. One remaining change compared to 2.x is RailsAdmin::Config#model no longer returns the model when given a block. With the removal of LazyModel in e4ae669 it is tricky to both defer initialization and return the model class. Fixes railsadminteam#3490
q3aiml
added a commit
to q3aiml/rails_admin
that referenced
this issue
Mar 10, 2022
Attempt to restore 2.x config loading behavior where 1) initializer config block evaluates immediately so that routes are configured correctly while 2) per-model config blocks only evaluate after all the models are loaded and associations are defined. One remaining change compared to 2.x is RailsAdmin::Config#model no longer returns the model when given a block. With the removal of LazyModel in e4ae669 it is tricky to both defer initialization and return the model class. Fixes railsadminteam#3490
q3aiml
added a commit
to q3aiml/rails_admin
that referenced
this issue
Mar 10, 2022
Attempt to restore 2.x config loading behavior where 1) initializer config block evaluates immediately so that routes are configured correctly while 2) per-model config blocks only evaluate after all the models are loaded and associations are defined. One remaining change compared to 2.x is RailsAdmin::Config#model no longer returns the model when given a block. With the removal of LazyModel in e4ae669 it is tricky to both defer initialization and return the model class. Fixes railsadminteam#3490
q3aiml
added a commit
to q3aiml/rails_admin
that referenced
this issue
Mar 10, 2022
Attempt to restore 2.x config loading behavior where 1) initializer config block evaluates immediately so that routes are configured correctly while 2) per-model config blocks only evaluate after all the models are loaded and associations are defined. One remaining change compared to 2.x is RailsAdmin::Config#model no longer returns the model when given a block. With the removal of LazyModel in e4ae669 it is tricky to both defer initialization and return the model class. Fixes railsadminteam#3490
q3aiml
added a commit
to q3aiml/rails_admin
that referenced
this issue
Mar 10, 2022
Attempt to restore 2.x config loading behavior where 1) per-model config blocks only evaluate after all the models are loaded and associations are defined while 2) initializer config block evaluates immediately so that routes are configured correctly. One remaining change compared to 2.x is RailsAdmin::Config#model no longer returns the model when given a block. With the removal of LazyModel in e4ae669 it is tricky to both defer initialization and return the model class. Fixes railsadminteam#3490
q3aiml
added a commit
to q3aiml/rails_admin
that referenced
this issue
Mar 10, 2022
Attempt to restore 2.x config loading behavior where 1) per-model config blocks only evaluate after all the models are loaded and associations are defined while 2) initializer config block evaluates immediately so that routes are configured correctly. One remaining change compared to 2.x is RailsAdmin::Config#model no longer returns the model when given a block. With the removal of LazyModel in e4ae669 it is tricky to both defer initialization and return the model class. Fixes railsadminteam#3490
q3aiml
added a commit
to q3aiml/rails_admin
that referenced
this issue
Mar 25, 2022
Attempt to restore 2.x config loading behavior where 1) per-model config blocks only evaluate after all the models are loaded and associations are defined while 2) initializer config block evaluates immediately so that routes are configured correctly. One remaining change compared to 2.x is RailsAdmin::Config#model no longer returns the model when given a block. With the removal of LazyModel in e4ae669 it is tricky to both defer initialization and return the model class. Fixes railsadminteam#3490
Closed by #3541. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
While testing an upgrade from rails_admin 2.x to
3.0.0.rc3
, I noticed that a number of our association fields were incorrectly using theString
type. Previously on 2.x these fields correctly used an association type such asBelongsToAssociation
.I tracked this down to a behavior change when
rails_admin
config is defined in a model before the associations. In 2.x the execution of therails_admin
block is deferred and runs after the associations are defined. In 3.x the block runs immediately. As a result in 3.x any field declarations effectively disable the field factories and force a string type. The declarations no longer modify an existing field automatically created from the association and instead create the field.I believe this may be caused by e4ae669.
Reproduction steps
Here is a standalone example. Uncomment the relevant
gemfile
section for either 2.x or 3.x.The output on 2.x:
The output on 3.x:
Expected behavior
For our use ideally the 2.x behavior would be reinstated. We separate our per-model config into concerns and we group the includes of concerns near the top of our models. We could simply move our includes but the risk remains that someone could define the
rails_admin
config in the wrong place in the future and be confused when association fields do not work as expected.That said this is a major release and I do think the reloading of config in development mode is a large productivity boost. Perhaps those and other benefits are worth sacrificing the past behavior. If so I think the change is worthy of a note in the upgrade docs. Ideally there would also be a way to warn when a field is defined prior to its association, but I don't have a solution handy for that.
If sticking with the new behavior I think it may also make sense to update the
RailsAdmin.config
comment which seems to hint that config block execution will be deferred later than it now is:rails_admin/lib/rails_admin.rb
Lines 20 to 23 in 94e599b
Additional context
rails
version: 7.0rails_admin
version: 3.0.0.rc3❤️ thanks so much for all the work on rails_admin ❤️
The text was updated successfully, but these errors were encountered: