如何按活动记录中的特定条件订购?

时间:2013-10-27 01:58:12

标签: ruby-on-rails activerecord ruby-on-rails-4 rails-activerecord rails-postgresql

要列出我数据库中的所有商店,我有查询

@shops = Shop.includes(:opening_times)
             .references(:opening_times)
             .limit(paging)
             .offset(@offset)

如果我想只获得现在开放的商店,我可以添加

.where("opening_times.day =?", today) #Open today
.where("opening_times.opens <= ?", @now)  #Opening time is before now
.where("(opening_times.opens+opening_times.open_for) > ?", @now)  #Closing time is after now
.order("opening_times.opens+opening_times.open_for") #Order by earliest opening time

但我需要的是列出所有商店,以及当前在顶部开放的商店。是否有任何方法可以根据列表是否符合当前打开的条件对列表进行排序?

这是使用postgres。

0 个答案:

没有答案
相关问题