带羽毛的排序查询

时间:2018-06-22 13:06:42

标签: sequelize.js feathersjs feathers-sequelize feathers-hook

我正在尝试编写一个挂钩,该挂钩将具有关联关系的表的排序添加到查询中。我的查询是在'points'上,它具有一个联接表'point_photos',然后将m:n关联到'photos'。标准的feathersjs $ sort不能用于关联的排序,因此我尝试在钩子中设置后缀'order',并且效果出色。现在,我想从查找查询中设置“订单”:

        return app.service('points').find(
          {
            query: {
              point_id: [1, 2, 5],
              include: ['PointPhotos'],
              order: [
                [
                  'point_id',
                  'DESC'
                ],
                [
                  'PointPhotos',
                  'photo_id',
                  'DESC'
                ]
              ]
            }
          }
        );
      })

但是现在我得到了:

error:  SequelizeDatabaseError: column points.order does not exist

这对我来说很奇怪,因为hook.params.sequelize在我看来对于钩子和查询都是相同的...

另外,当我简化查找查询“ order”时,也会遇到相同的错误;不允许在查询对象中添加“订单”?

编辑: 我设法通过将命令添加到“ include”选项中来解决它:

return app.service('points').find(
              {
                query: {
                  point_id: [1, 2, 5],
                  include: { include: ['PointPhotos'], order: [
                    [
                      'point_id',
                      'DESC'
                    ],
                    [
                      'PointPhotos',
                      'photo_id',
                      'DESC'
                    ]
                  ]
                 }
                }
              }
            );
          })

并相应地调整我的关联钩子。尽管有点像“顺序”和“包含”处于同一级别,但这有点愚蠢,因此使事情变得混乱。我的问题仍然可以归结为:查询对象中的“ order”键为什么不起作用?看起来它某种程度上被认为是表字段。

0 个答案:

没有答案
相关问题