我有模特
class PatientVisitDetail < ActiveRecord::Base
belongs_to :procedure_code
scope :billable, -> { includes(:procedure_code).where('procedure_codes.type_code IN (6,7)')}
end
并且
class ProcedureCode < ActiveRecord::Base
has_many :patient_visit_details, :dependent => :destroy
end
当我通过查询搜索记录时,如
patient_visit_details.includes(:procedure_code).where("procedure_codes.type_code IN (6,7)")
然后出现以下错误
Mysql2::Error: Unknown column 'procedure_codes.type_code' in 'where clause': SELECT COUNT(*) FROM `patient_visit_details` WHERE `patient_visit_details`.`deleted_at` IS NULL AND (patient_visit_id > 0) AND `patient_visit_details`.`patient_visit_id` = 6 AND (procedure_codes.type_code IN (6,7))
type_code存在于数据库中,但仍然是未知列。