我有以下两种型号
class Machine < ApplicationRecord
has_many :machine_part_changes
has_one :current_identifier_part_change, -> {
sql = <<-SQL
INNER JOIN "machine_parts"
ON "machine_parts"."id" = "machine_part_changes"."machine_part_id"
AND "machine_parts"."is_machine_external_identifier" = 1
SQL
installed.joins(sql)
},
class_name: 'MachinePartChange'
end
class MachinePartChange < ApplicationRecord
belongs_to :machine_part
belongs_to :machine, touch: true
end
在rails 4.2中我能够做到
Machine.eager_load(:current_identifier_part_change).first
但是现在升级到Rails 5.2后,在运行测试时出现以下错误。
Failure/Error: machine = Machine.eager_load(:current_identifier_part_change).find(create_machine.id)
NoMethodError:
undefined method `expr' for nil:NilClass
我对sql :-(不太了解,并且代码是由其他开发人员编写的,我该怎么做才能通过此测试。