我有一个表Person的ActiveRecord数组(:id,:name,:city_id,:work_id,:date)。例如:
[<Person id: 4, name: John, city_id: 10, work_id: 1, date: 2015-10-10>,
<Person id: 5, name: Jack, city_id: 11, work_id: 2, date: 2015-10-08>,
<Person id: 8, name: John, city_id: 10, work_id: 2, date: 2015-10-11>,
<Person id: 9, name: John, city_id: 10, work_id: 3, date: 2015-10-11>,]
对于特定的人,我想要具有最大日期的行。因此,对于Jack,我将得到id = 5的行。对于John,我将得到id = [8,9]的行,因为这些行的日期是最大的。我无法在Rails中找到一种有效的方法。请帮忙。
答案 0 :(得分:1)