【问题标题】:Feathers-Sequelize Where statement and Query paramFeathers-Sequelize Where 语句和查询参数
【发布时间】:2018-08-03 12:03:40
【问题描述】:

我有以下羽毛续集查询:

context.params.sequelize = {
    raw: false,
    include: [{
      model: organisations,
      where: organisationId ? { id: organisationId } : undefined,
      include: [{
        model: roles,
        where: roleId ? { id: roleId } : undefined,
      }],
    }],
    where: single ? (
      sequelize.and(
        sequelize.where(
          sequelize.col('"organisations->organisation_users"."roleId"'),
          sequelize.col('"organisations->roles"."id"'),
        ),
        sequelize.where(
          sequelize.col('"organisations->organisation_users"."userId"'),
          sequelize.col("users.id")
        )
      )
    ) : undefined
  }

我提出以下服务请求:

await UserService.find({ query: { email: data.email } }))

查询对象被遗漏了,因为在上面的 sequelize 查询中我设置了自己的 where 语句。如果我删除 where 语句,则查询对象将起作用。如何使用自己的 where 语句并包含羽毛查询对象?

谢谢你和问候,

埃米尔

【问题讨论】:

    标签: sequelize.js feathersjs feathers-sequelize


    【解决方案1】:

    为了向现有查询对象添加额外的条件,而不是使用 params.sqeuelize将它们直接添加到查询对象中(因为它可以通过上下文使用.params.query) 并且由于您使用了 before 钩子,因此查询对象在执行之前会被修改。 在你的例子应该是这样的:

    if(single) {
        context.params.query.push(
          sequelize.and(
            sequelize.where(
              sequelize.col('"organisations->organisation_users"."roleId"'),
              sequelize.col('"organisations->roles"."id"'),
            ),
            sequelize.where(
              sequelize.col('"organisations->organisation_users"."userId"'),
              sequelize.col("users.id")
            )
          )
       )
    }
    

    可能不是正确的语法,但这就是想法:直接在羽毛查询对象中添加额外的条件。希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2018-09-25
      • 1970-01-01
      • 2016-07-09
      • 1970-01-01
      • 2015-05-25
      • 2014-05-26
      • 1970-01-01
      • 2021-06-16
      • 2015-07-06
      相关资源
      最近更新 更多