简体   繁体   English

Sequelize id (pk) 列无效值

[英]Sequelize id (pk) column invalid value

I have here a where condition in which I need to find things that are not equal to the ID field (primary key) of the staff members table,我在这里有一个 where 条件,我需要找到不等于工作人员表的 ID 字段(主键)的东西,

however for some reason when the program returns the promise it tells me 'Invalid value { id: 1 }'但是由于某种原因,当程序返回 promise 时,它告诉我“无效值 { id: 1 }”

id is the name of the column in the db, and there is an entry associated with the value. id 是 db 中列的名称,并且有一个与该值关联的条目。

The comments are the older code from sequalize 3 being ported to 6.注释是从 sequalize 3 移植到 6 的旧代码。

exports.getAllStaffMembers = async (request, reply) => {
  const attributes = ['id', 'accessLevel', 'emailAddress', 'firstName', 'lastName', 'phoneNumber', 'profilePictureHash'];
  let where = {
    [Op.ne]: [{ id: request.auth.credentials.id }]
  }
  // `"staffMember"."id" <> ${request.auth.credentials.id}`;

  if (request.query.rank) {
    where[Op.and] =
    {
      accessLevel: request.query.rank
    }

    // where = `${where} AND (1
    //   "staffMember"."accessLevel" = '${request.query.rank}'
    // )`;
  }

  const staffMembers = await model.staffMember.findAndCountAll(_.assign({},
    requestHelper.computePaginationObject(request.query.limit, request.query.page), {
    attributes,
    where: [where],
    order
  }));

what am I doing wrong / how do I use the values in the primarykey id column?我在做什么错/如何使用主键 id 列中的值?

You should indicate the column name on the upper level and an operator on the lower level.您应该在上层标明列名,在下层标明运算符。 Like this:像这样:

let where = {
    id: { [Op.ne]: request.auth.credentials.id }
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM