简体   繁体   English

Sequelize 获取最后更新或创造价值

[英]Sequelize get last update or create value

I need to find the latest create or update entry in a table and return.我需要在表中找到最新的创建或更新条目并返回。

Example例子

const data = MyModel.findOne({
   where: { id },
   ordered: [[ //createdAt and updatedAt]]   

})
console.log(data.exampleLastUpdateOrCreateValue)

How can I do this?我怎样才能做到这一点?

Can you try doing this way你能试试这样做吗

const data = MyModel.findOne({
   where: { id },
   order: [['updatedAt', 'DESC' ]]   

})
console.log(data.exampleLastUpdateOrCreateValue)

You can also make use of id if it auto-incremented如果它自动递增,您也可以使用id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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