Skip to content

"The option :class_name is deprecated." but I think it is still needed.  #2384

@gregmatthewcrossley

Description

@gregmatthewcrossley
  • What were you trying to do?
    I am defining some ATTRIBUTE_TYPES in a dashboard. One of my attributes (lead_practitioners) is a belongs_to relation where its class name doesn't match the relation name. My model defines this belongs_to relation like so:
class Practice < ApplicationRecord
  has_many :practitioner_practices, inverse_of: :practice, dependent: :destroy
  has_many :practitioners, through: :practitioner_practices
  has_many :lead_practitioners, -> { where(practitioner_practices: {lead: true}) }, through: :practitioner_practices, source: :practitioner
  ...
  • What did you end up with (logs, or, even better, example apps are great!)?
    I am using the class_name option when I define the attribute in the dashboard file, like this:
ATTRIBUTE_TYPES = {
   ...
    lead_practitioner: Field::BelongsTo.with_options(class_name: "Practitioner"),
    ...
 }

which works, but warns me with this:

DEPRECATION WARNING: The option :class_name is deprecated. Administrate should detect it automatically. Please file an issue at https://github.com/thoughtbot/administrate/issues if you think otherwise.

If I remove the class_name option and let the Administrate gem try to determine the class name on its own, I get this error:

ActionView::Template::Error:
       undefined method `klass' for nil:NilClass
     
               reflection(resource_class, attr).klass

Even if I explicitly add the class name to the model relation, like so:

  has_many :lead_practitioners, -> { where(practitioner_practices: {lead: true}) }, through: :practitioner_practices, source: :practitioner, class_name: "Practitioner"

I get the same error as above.

  • What versions are you running?
    • Rails: 7.0.4
    • administrate: 0.18.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugbreakages in functionality that is implemented

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions