续集 findOne 最新条目

编程入门 行业动态 更新时间:2024-10-23 16:27:23
本文介绍了续集 findOne 最新条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要在表格中找到最新的条目.做这个的最好方式是什么?该表具有 Sequelize 的默认 createdAt 字段.

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.

推荐答案

Method findOne 是 findAll 方法的包装器.因此,您可以简单地使用 findAll 限制为 1 并按 id 降序排序.

Method findOne is wrapper for findAll method. Therefore you can simply use findAll with limit 1 and order by id descending.

示例:

YourModel.findAll({ limit: 1, where: { //your where conditions, or without them if you need ANY entry }, order: [ [ 'createdAt', 'DESC' ]] }).then(function(entries){ //only difference is that you get users list limited to 1 //entries[0] });

更多推荐

续集 findOne 最新条目

本文发布于:2023-10-14 21:56:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492326.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:条目   续集   最新   findOne

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!