N
N
narem2022-01-30 23:46:50
Node.js
narem, 2022-01-30 23:46:50

How to search through all connected tables?

Orm sequelize
There is a request, it has several tables connected. I need to search all tables and return the found value. At the moment like this:

models.db.employe.findAll({
    order: ,
    include: [{
      model: models.db.categorySubcategory,
      include: [{
        model: models.db.category
      },
      {
        model: models.db.subCategory
      }]
    },
    {
      model: models.db.personRank,
      include: [{
        model: models.db.person
      },
      {
        model: models.db.rank
      }]
    },
    {
      model: models.db.phone,
      where:{
        phone:{
          [Op.substring]: `${request.query.data}`
        }
      }
    },
    {
      model: models.db.mainPhone,
      where:{
        mainPhone:{
              [Op.substring]: `${request.query.data}`
        }
      }
    }]
  })

But it doesn't work quite the way I want it to. Now the search occurs with 2 matches in the connected tables, but I need at least 1 match. I tried required: false but in this case, whatever content of the request I'm looking for - will return all records.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question