简体   繁体   中英

sequelize users.findOne using two parameters

I would like to use users.findOne method using two params like in the example below, not just with the id or name but with both

 const user = await Tags.findOne({
    where: { id: ID, name: NAME },
  });

As far as I know you code should work, but you can try the following approach:

const user = await Tags.findAll({
  where: {
    [Op.and]: [
      { id: ID },
      { name: NAME }
    ]
  }
});

You can define operators for the where clause manually. For reference see https://sequelize.org/master/manual/model-querying-basics.html#applying-where-clauses

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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