-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
The class_name
option is still necessary for namespaced associated classes in Field::HasMany
#1978
Comments
Thank you for reporting. I have very little experience with ActiveStorage so I don't have any immediate solutions. I'll have to experiment. Can you be more specific as to what error you get? For example, can you provide an exception backtrace? For the moment, a way to silence this warning would be to override |
Here's the exception backtrace from one of my tests that fails if I remove the
So it looks like that it's not handling the namespace because it should be |
Please please please do not deprecate this, it will break everything in our systems. We have multiple level namespaces like |
I also encountered this issue with removing the In my case, the only places where Administrate failed to automatically determine the It's actually not clear to me how ActiveRecord was able to function without specifying the Now there is one case (for us) where we do still need to set the
One potential improvement for this situation might be for Administrate to first determine if there is any I'm happy to submit a PR if there's any interest in this approach. Thanks! |
I encounter the same issue as described in the OP with Administrate 0.16.0. I needed to use # app/initializers/administrate.rb
module Administrate
def self.warn_of_deprecated_option(name)
end
end NB: The ActiveStorage admin routes were configured as shown here. |
I applied the following patch without using the :class_name option and it worked fine
|
A similar problem happens to me when dashboards are namespaced on Given, we have namespaced dashboards:
# package_dashboard.rb
require 'administrate/base_dashboard'
module System
class PackageDashboard < Administrate::BaseDashboard
ATTRIBUTE_TYPES = {
id: Field::Number,
build: Field::BelongsTo.with_options(
class_name: 'System::Build'
)
... The dashboard above works fine, but crashes without
Reproducible for both BelongsTo/HasMany field types. |
If the associated class is `System::Build`, the previous code would tell us that the name was `Build`. This code gets the right name. Example taken from thoughtbot#1978 (comment), which I reproduced locally.
Thank you all for your feedback. I appear to have time to look into this finally. I started by reproducing @aliaksandrb's example, and was able to get a first stab at a fix (pretty much by following @unosk's example). This initial fix is at main...pablobm:namespaced-associations. Would some of you be able to try it out and see if it helps? Meanwhile I'll try some more complex stuff, like ActiveStorage, etc. Let's try squash this bug together! |
@pablobm thanks for looking into it! I've applied the patch provided, and it seems to be working fine for both BelongsTo/HasMany associations. Tested using |
FYI: This looks related/might be affected by the change: #2209 |
If the associated class is `System::Build`, the previous code would tell us that the name was `Build`. This code gets the right name. Example taken from thoughtbot#1978 (comment), which I reproduced locally.
If the associated class is `System::Build`, the previous code would tell us that the name was `Build`. This code gets the right name. Example taken from thoughtbot#1978 (comment), which I reproduced locally.
@andrewdsmith - I have been able to replicate your exact issue, and for me it's solved with the suggested fix. I have created at PR for it at #2235. Would you be able to check that it works for you too? |
If the associated class is `System::Build`, the previous code would tell us that the name was `Build`. This code gets the right name. Example taken from thoughtbot#1978 (comment), which I reproduced locally.
If the associated class is `System::Build`, the previous code would tell us that the name was `Build`. This code gets the right name. Example taken from thoughtbot#1978 (comment), which I reproduced locally.
Fixes thoughtbot#1978 This includes the namespace of the associated class. If the associated class is `System::Build`, the previous code would tell us that the name was `Build`. This code gets the right name.
Fixes #1978 This includes the namespace of the associated class. If the associated class is `System::Build`, the previous code would tell us that the name was `Build`. This code gets the right name.
For now, we have merged the fix, which we think will solve this issue. Please let us know if you think otherwise. |
What were you trying to do?
Silence the
class_name
option deprecation warnings due to #1633.What did you end up with (logs, or, even better, example apps are great!)?
I was able to remove all uses of the
class_name
option except the following:Notably, I also have a dashboard for
ActiveStorage::Attachment
that has aField::HasOne
back to the blob that doesn't require theclass_name
option.What versions are you running?
Rails: 6.0.3.7
administrate: 0.16
The text was updated successfully, but these errors were encountered: