Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

237
Views
seleccione los registros siguientes y anteriores en Sequelize en función de createdAt

Lo que quiero: obtener un registro de la base de datos en función de su ID (UUID) y recuperar los registros anteriores y siguientes también

Asociaciones : posts N:M categories, posts 1:N comments, posts N:1 users, posts N:M tags, posts 1:N post_views

Solución actual:

 const post = await PostModel.findByPk(id, { include: [ { model: CategoryModel, attributes: ['title'] }, { model: TagModel }, { model: CommentModel, include: { model: UserModel } }, { model: PostViewModel }, { model: UserModel, attributes: ['fullname', 'id', 'avatar'] } ] }); const nextPost = await PostModel.findOne({ where: { createdAt: { [Op.gt]: post.createdAt }} const prevPost = await PostModel.findOne({ where: { createdAt: { [Op.lt]: post.createdAt }} });

pero creo que esto no es eficiente y bueno.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!