控制器代码:
@fte_new_hires = Bvadmin::EmployeeApplicant.fte_new_hires(next_startdate, next_enddate)
型号代码:
class Bvadmin::EmployeeApplicant < Bvadmin::Record
self.table_name = "BVADMIN.EMPLOYEE_APPLICANTS"
self.primary_key = :applicant_id
has_many :employeeapplications
scope :fte_new_hires, -> (startdate,enddate) {EmployeeApplicant.joins (:employeeapplications).where("confirmed_eod >= ? and confirmed_eod <= ?", startdate, enddate).order('name ASC') }
end
获取以下错误:
未初始化的常量Bvadmin :: EmployeeApplicant :: EmployeeApplicant
答案 0 :(得分:0)
您的班级名称是&#39; Bvadmin :: EmployeeApplicant&#39;,但您使用了&#39; EmployeeApplicant&#39;在范围内,所以它试图找到不变的EmployeeApplicant&#39;在这个班级&#39; Bvadmin :: EmployeeApplicant&#39;,这就是为什么你得到了未初始化的常量Bvadmin :: EmployeeApplicant :: EmployeeApplicant&#39;错误
joins is equivalent to self.joins which is equivalent to Bvadmin::EmployeeApplicant.joins
本课程中的自我是Bvadmin :: EmployeeApplicant,所以你可以这样做,
已更新
scope :fte_new_hires, -> (startdate,enddate) {joins(:employee_applications).where("confirmed_eod >= ? and confirmed_eod <= ?", startdate, enddate).order('name ASC') }
如下所示更改您的协会:
has_many :employee_applications, class: "Bvadmin::EmployeeApplicantion"