class EcScoreLevel < ApplicationRecord belongs_to :ec_course default_scope { order(position: :asc) } def compare_condition max_position = self.class.maximum(:position) # 特殊情况:只有一条记录 position < max_position || max_position == 1 ? 'not_less_than' : 'less_than' end end