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

HasMany field used for a relation (but not an association) #1834

Open
such opened this issue Nov 26, 2020 · 1 comment
Open

HasMany field used for a relation (but not an association) #1834

such opened this issue Nov 26, 2020 · 1 comment
Labels
bug breakages in functionality that is implemented

Comments

@such
Copy link

such commented Nov 26, 2020

  • What were you trying to do?

I've updated administrate to master and following #1633 some of my dashboards are broken.
We are (ab)using the HasMany field for displaying relations that are not associations:

class Customer
  def fellow_customers_that_are_hard_to_represent_with_an_association
    Customer.scope.where...
  end
end
class CustomerDashboard < Administrate::BaseDashboard
  ATTRIBUTE_TYPES = {
    fellow_customer: Field::HasMany.with_options(class_name: 'Customer'),
  }
end
  • What did you end up with (logs, or, even better, example apps are great!)?
ActionView::Template::Error:
       undefined method `class_name' for nil:NilClass
       Did you mean?  class_eval
     # ./vendor/ruby/2.7.0/bundler/gems/administrate-0f8624ca1d24/lib/administrate/field/associative.rb:15:in `associated_class_name'
     # ./vendor/ruby/2.7.0/bundler/gems/administrate-0f8624ca1d24/lib/administrate/field/associative.rb:44:in `associated_class_name'
     # ./vendor/ruby/2.7.0/bundler/gems/administrate-0f8624ca1d24/lib/administrate/field/associative.rb:37:in `associated_dashboard'
     # ./vendor/ruby/2.7.0/bundler/gems/administrate-0f8624ca1d24/lib/administrate/field/has_many.rb:82:in `includes'
     # ./vendor/ruby/2.7.0/bundler/gems/administrate-0f8624ca1d24/lib/administrate/field/has_many.rb:57:in `resources'
  • What versions are you running?
    • Rails: 6.0.3.2
    • administrate: master

This pattern is still useful I think. I've tried converting those methods to associations and it's not always possible.
Can the behaviour of the former HasMany be restored in a new Field type maybe?

@such such added the bug breakages in functionality that is implemented label Nov 26, 2020
@pablobm
Copy link
Collaborator

pablobm commented Nov 26, 2020

Uh, that's an interesting use case; thank you for letting us know. My initial thought is that it could be solved with a new field type, although I'm not 100% sure. Would you be able to give it a go?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug breakages in functionality that is implemented
Projects
None yet
Development

No branches or pull requests

2 participants