Skip to content
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

Guess correct class name for namespaced associations #2235

Merged
merged 1 commit into from
Aug 8, 2022

Conversation

pablobm
Copy link
Collaborator

@pablobm pablobm commented Aug 4, 2022

Fixes #1978 #2209

At lib/administrate/field/associative.rb, we are currently using the wrong incantation to figure out the name of the associated class. What we have works most of the time, but will drop the namespace if there's one.

For example: if Blog::Post.has_many :tags of type Blog::Tags, it will incorrectly guess that the class name of :tags is "Tag" instead of "Blog::Tag".

This breaks the Blog::PostDashboard, which thinks it has to link to TagDashboard instead of Blog::TagDashboard.

The fix is just the one liner in that file. The rest is putting together an instance of this in the example app, and a spec to test it.

spec/example_app/db/schema.rb Show resolved Hide resolved
spec/example_app/db/schema.rb Show resolved Hide resolved
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.
@nickcharlton nickcharlton force-pushed the namespaced-associations branch from b991698 to 01547f5 Compare August 8, 2022 12:05
@nickcharlton nickcharlton merged commit ea96c83 into thoughtbot:main Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The class_name option is still necessary for namespaced associated classes in Field::HasMany
2 participants