简体   繁体   中英

Rails - find record with highest month/year

I'm kinda stuck in a select query question: I have a Bill model, which contains two integer attributes: month and year. I would like to retrieve the more recent record (highest date) so I can check an attribute value on it. Any ideas for solving that problem, since month and year are independent attributes? Thanks!

Bill.order('year DESC, month DESC').first

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM