简体   繁体   中英

Rails, find object before last e.g -1

Afternoon all,

I have this query and was wondering how i could convert this into finding the last but one record so instead of .last it would get -1. ( I have read Rails: how to find record before last? but i'm not sure how to convert this query)

The code;

Model.last.hotels.find_by_winner(true)

many thanks in advance! Andy

Model.order('id desc').offset(1).first.hotels.find_by_winner(true)

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