Sequelize findOne latest entry

Noah picture Noah · Feb 17, 2016 · Viewed 61k times · Source

I need to find the latest entry in a table. What is the best way to do this? The table has Sequelize's default createdAt field.

Answer

szym picture szym · Nov 30, 2016
model.findOne({
    where: { key },
    order: [ [ 'createdAt', 'DESC' ]],
});