administrate
                                
                                
                                
                                    administrate copied to clipboard
                            
                            
                            
                        Allow the specification of resource class names for associative fields
- What would you like to be able to do? Can you provide some examples?
- I would like to create a HasMany field for an association whose name is not the same as the associated class name, e.g.
If I add a fieldclass Foo < ApplicationRecord has_many :foo_bars has_many :pubs, through: :foo_bars, source: :bar end class FooBar < ApplicationRecord belongs_to :foo belongs_to :bar endpubs: Field::HasManywithout specifyingclass_name: Barin theFooDashboard, Administrate will look for aPubDashboardinstead of theBarDashboard. As per #1633class_nameis now deprecated, but all of the field should accept theresource_classoption. However, it currently isn't being used to determine the class name for (at least) theHasManyfield type. 
 - I would like to create a HasMany field for an association whose name is not the same as the associated class name, e.g.
 - How could we go about implementing that?
- Leverage the non-deprecated 
resource_classoption in the associative fields to determine the resource class if the association has a different name. 
 - Leverage the non-deprecated 
 - Can you think of other approaches to the problem?
- Not at the moment
 
 
Thanks!
Thank you for reporting this issue. In theory, the correct class should be detected through reflection at Administrate::Field::Associative, specifically here:
https://github.com/thoughtbot/administrate/blob/84084235463a6761f25108382cb81c13632d2052/lib/administrate/field/associative.rb#L14-L16
Would you be able to have a look there and see what's going on?
Yeah let me do a little more digging and follow up. Thanks!
I'm seeing this too, on a has_one with a class_name: option.  When we test reflection(resource_class, attr).class_name from the console we do get the expected class name.
I believe the issue has to do something with class load order – since we're declaring those attributes as statics on the dashboard class, they're getting loaded before the AR models are completed initialized. I'll try to make some time to dig into this deeper.
I think this should be fixed by https://github.com/thoughtbot/administrate/pull/2292