Sequelize relation with WHERE IN (“ARRAY”)

后端 未结 2 761
迷失自我
迷失自我 2021-01-18 05:29

Is it possible to define a relationships in sequelize where multiple foreign keys are stored as an array in one field. Basically a belongsToMany but instead of an relation t

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-18 06:00

    To get sequelize query result with where condition for given array with using **Op.in** code to find result with in array as

    var Sequelize = require('sequelize');
    var Op = Sequelize.Op;
    var arrayofTaskId = ['123', '456', '789'];
    Tasks.findAll({
      where: {
        task_id: {
          [Op.in]: arrayofTaskId
        }
      }
    }).then(function(result) {
      return res.json(result)
    });
    

提交回复
热议问题