0
我有以下四個領域的典範:MySQL的排序按分組日期範圍
scope :active, -> { where("start_at <= '#{Time.now.utc}' AND end_at > '#{Time.now.utc}'") }
scope :ended, -> { where("end_at < '#{Time.now.utc}'") }
scope :coming_soon, -> { where("start_at > '#{Time.now.utc}' AND start_at < '#{Time.now.utc+6.hours}'") }
我希望能夠像做(僞代碼,只是想給一個想法):
Model.all.order(active, coming_soon, ended)
結果將是該表中的所有行,按滿足active
限制的行進行排序,然後是滿足coming_soon
限制的行,最後是滿足ended
約束條件的行。