Разделить запрос findAll с транзакцией и с использованием лимита и сместить его не работает - PullRequest
1 голос
/ 11 марта 2020

Я пытаюсь добавить нумерацию страниц, используя транзакцию при секвелировании, но когда я добавляю и предел, и смещение, он отображает ошибку как SequelizeDatabaseError: Неверное имя столбца 'typeId'.

try {
    await sequelize.transaction(async (transaction) => {
        data = await Test.findAll({
          order: [['id', 'DESC']],
          where: { type: 'Y' },
          attributes: ['id', 'type', 'name'],
          include: [
            {
                model: xyz,
                as: 'xyz',
                attributes: ['id'],
                include: {
                    model: efg,
                    as: 'efg',
                    attributes: ['id', 'typeId'],
                },
            },
            {
                model: abc,
                as: 'abc',
                attributes: ['id'],
                include: {
                    model: ijk,
                    as: 'ijk',
                    attributes: ['id', 'name'],
                },
            }
          ],
          transaction,
          limit: 10,
          offset: 0,
        }).then(res=>{
          return res;
        })
      });
} catch(e) {

}

Любой совет будет очень признателен , Спасибо!

1 Ответ

0 голосов
/ 11 марта 2020

Вам необходимо указать в качестве второго аргумента транзакцию:

try {
    await sequelize.transaction(async (transaction) => {
        data = await Test.findAll({
          order: [['id', 'DESC']],
          where: { type: 'Y' },
          attributes: ['id', 'type', 'name'],
          include: [
            {
                model: xyz,
                as: 'xyz',
                attributes: ['id'],
                include: {
                    model: efg,
                    as: 'efg',
                    attributes: ['id', 'typeId'],
                },
            },
            {
                model: abc,
                as: 'abc',
                attributes: ['id'],
                include: {
                    model: ijk,
                    as: 'ijk',
                    attributes: ['id', 'name'],
                },
            }
          ],
          // comment the line below
          // transaction,
          limit: 10,
          offset: 0,
        },
        { transaction }
        ).then(res=>{
          return res;
        })
      });
} catch(e) {

}

Я знаю, что Официальная документация описывает выполнение транзакции для метода findAll, как вы реализовали, но это в моем случае, когда я пытался, не получилось так, как ожидалось.

...