Node Sequelize中热切加载的模型的排序结果 [英] Ordering results of eager-loaded models in Node Sequelize

查看:66
本文介绍了Node Sequelize中热切加载的模型的排序结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组复杂的关联模型。这些模型使用联接表进行关联,每个联接表都有一个称为订单的属性。我需要能够查询父模型'Page'并包括关联的模型,并按字段'order'对这些关联进行排序。

I have a complex set of associated models. The models are associated using join tables, each with an attribute called 'order'. I need to be able to query the parent model 'Page' and include the associated models, and sort those associations by the field 'order'.

以下内容没有对结果排序顺序的影响:

The following is having no effect on the results' sort order:

db.Page.findAll({
  include: [{
    model: db.Gallery,
    order: ['order', 'DESC'],
    include: [{
      model: db.Artwork,
      order: ['order', 'DESC']
    }]
  }],
})


推荐答案

我相信您可以做到:

db.Page.findAll({
  include: [{
    model: db.Gallery
    include: [{
      model: db.Artwork
    }]
  }],
  order: [
    [ db.Gallery, 'order', 'DESC' ],
    [ db.Gallery, db.ArtWork, 'order', 'DESC' ]
  ]
})

这篇关于Node Sequelize中热切加载的模型的排序结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆