以下查询在某些情况下返回 nil
scope :claim_one, where(" location_id IS NULL OR start_time IS NULL OR archived IS NULL " ).includes(:instructor_assignments).where('instructor_assignments.user_id IS NULL')
我想将查询转换为 lambda 函数,该函数处理查询返回的 nil,如下所示;
scope :claim, (lambda do |claim| where(" location_id IS NULL OR start_time IS NULL OR archived IS NULL ").includes(:instructor_assignments).where('instructor_assignments.user_id IS NULL', claim ) unless claim.nil? end )
后者不起作用,因为我认为它没有正确的 rails 语法
谢谢