鉴于结果传递给
ids = [4, 2, 1, 3]
dishes = Dish.where("restaurant_id in (?)", ids)
是否可以基于ID的顺序排序的菜?
=> # I'd like to see something like this
=> dishes.map(&:restaurant_id)
=> [4, 4, 4, 4, 4, 2, 2, 2, 1, 1, 1, 1, 3, 3, 3, 3] etc.
I'm currently getting something like this
=> [1, 4, 3, 4, 4, 3, 3, 2, 3, 2, 4, 4, 4, 3, 4, 2, 2, 2, 2, 4, 3, 1, 1, 1, 3, 2, 2, 1, 4]
我知道我可以要么通过IDS循环,然后只是select
菜匹配,则给定id重建的磁盘阵列,但我不能这样做,因为我还是想在关联使用will_paginate
。
任何帮助或提示,将不胜感激,谢谢!
以及如何现将结果排序? –
Sergio让我编辑。 abjihit不会工作,因为restaurant_id有自己的顺序。 – lemon
对不起,我不明白你的问题,我打了很简单:Dishes.where(“restaurant_id in(?)”,ids).order(“restaurant_id desc”)。map {| j | j.restaurant_id} – abhijit