Rails Admin field filter in a has_one through relationship

53 Views Asked by At

I have a Remediation model which inherits from AssessmentHighRiskFactor model and added some custom show fields from other tables using relationships. The fields are visible and working fine, but I can't use the filter by 'cycle' in the admin panel (throws errors).

  • It is trying to access the cycle column which belongs to (institution_company_topics table) in the assessment_high_risk_factor table.
  • PG::UndefinedTable: ERROR: missing FROM-clause entry for table assessments or institution_company_topics
  • Unknown column (because it is not doing the filter in the corresponding table)
Remediation model:
class Remediation < AssessmentHighRiskFactor
  has_one :company, through: :assessment
  has_one :institution_company_topic, through: :assessment

  def cycle
    institution_company_topic&.cycle
  end

  rails_admin do
    def helper_text
      'Manage Remediation'
    end

    list do
      field :cycle do
        queryable true
        searchable true
        filterable true
      end
    end
end
  • Already tried with scopes (with custom query to join tables)
  • Using bindings objects
  • Using searchable [{InstitutionCompanyTopic => :cycle}] or [:cycle]
AssessmentHighRiskFactor model:
  class AssessmentHighRiskFactor < ApplicationRecord
    belongs_to :assessment
  end

Assessment model:
  class Assessment < ApplicationRecord
    belongs_to :institution_company_topic, optional: true
    has_many :assessment_high_risk_factors, dependent: :destroy
  end
InstitutionCompanyTopic model:
  class InstitutionCompanyTopic < ApplicationRecord
    has_many :assessments, dependent: :destroy
  end

gem 'rails_admin', '~> 2.1.0'

Any ideas would be good.

0

There are 0 best solutions below