title: How to set common where param to all models in query, in sequelize
body: <p>I'm trying to realize the query, where I can find all records, which at least one of the attributes includes the text, user send with request, for that I use where, but it can search, as I understand, in only own model, but i need it to search it in parent model and in associated filds together, not apart.</p>
  <p>There is my models:</p>
  <pre><code>const Picture = sequelize.define&lt;IPictureInstance&gt;('picture', {
     id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
     img: { type: DataTypes.STRING, allowNull: false },
     mainTitle: { type: DataTypes.STRING, allowNull: false },
     description: { type: DataTypes.TEXT }
  });
  
  const PictureInfo = sequelize.define&lt;IPictureInfoInstance&gt;('pictureInfo', {
     id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
     title: { type: DataTypes.STRING, allowNull: false },
     description: { type: DataTypes.STRING, allowNull: false }
  });
  
  const PictureTag = sequelize.define&lt;IPictureTagInstance&gt;('pictureTag', {
     id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
     text: { type: DataTypes.TEXT, allowNull: false }
  });
  
  const PicturesTags = sequelize.define&lt;IPicturesTagsInstance&gt;('picturesTags', {
     id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }
  });
  </code></pre>
  <p>And their associations:</p>
  <pre><code>Picture.belongsToMany(PictureTag, { through: PicturesTags, as: &quot;tags&quot;, onDelete: 'cascade' });
  PictureTag.belongsToMany(Picture, { through: PicturesTags, as: &quot;pictures&quot;, onDelete: 'cascade' 
  });
  
  Picture.hasMany(PictureInfo, { onDelete: &quot;cascade&quot; });
  PictureInfo.belongsTo(Picture);
  </code></pre>
  <p>That's what I tried to do:</p>
  <pre><code>  static async getPictures(query: string | undefined) {
  const pictures = await models.Picture.findAll({
    where: {
      [Op.or]: {
        mainTitle: { [Op.iRegexp]: `${query}` },
        description: { [Op.iRegexp]: `${query}` },
      },
    },
    include: [
      {
        model: models.PictureInfo,
        as: &quot;pictureInfos&quot;,
        where: {
          [Op.or]: {
            title: { [Op.iRegexp]: `${query}` },
            description: { [Op.iRegexp]: `${query}` }
          }
        },
        required: false
      },
      {
        model: models.PictureTag,
        as: &quot;tags&quot;,
        attributes: [&quot;id&quot;, &quot;text&quot;],
        where: { text: { [Op.iRegexp]: `${query}` } },
        through: {
          attributes: [],
        },
        required: false
      }
  
    ],
  
  });
    return pictures;
  }
  </code></pre>
  <p>But in this case, when it can't find records in first where param it returns an empty array, I understand it, but it isn't a behavior I need.</p>
  <p>I need to check every attribute together.</p>
  <p>So, if user send query=cat, it will check mainTitle and description, if there is nothing, it will check associated pictureInfos fields and after, if there is nothing, check pictureTags associated fields, that's what I need, will be grateful for the help.</p>