Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequelize missing FROM-clause entry for table Postgres

I am trying to filter my DataRow objects by where the included DataPoints data is loc and sortOrder is 2. Below is the query I am trying. I keep getting the following error.

SequelizeDatabaseError: missing FROM-clause entry for table "dataPoints"

I have tried setting required: true and duplicating: false with no luck. I tried these in both the DataRows include as well as DataPoints.

    attributes: ['id', 'name', 'labId'],
    include: [{
      as: 'dataColumns',
      model: DataColumn,
      attributes: ['id', 'name', 'sortOrder', 'dataType', 'isDate', 'isLocation'],
    }, {
      as: 'dataSets',
      model: Study,
      attributes: ['id', 'name'],
    }, {
      as: 'dataRows',
      model: DataRow,
      attributes: ['id'],
      where: {
        [Op.and]: [
          {
            '$dataPoints.data$': 'loc',
          },
          {
            '$dataPoints.sortOrder$': 2,
          },
        ],
      },
      include: [{
        as: 'dataPoints',
        model: DataPoint,
        attributes: ['id', 'sortOrder', 'data'],
      }],
    },],
    order: [
      [{ model: DataColumn, as: 'dataColumns' }, 'sortOrder', 'ASC'],
      [{ model: DataRow, as: 'dataRows' }, { model: DataPoint, as: 'dataPoints' }, 'sortOrder', 'ASC'],
    ],
  }
like image 525
EJ_Ozyazgan Avatar asked Nov 19 '20 04:11

EJ_Ozyazgan


1 Answers

Try required: true and duplicating: false on all the models that you're trying to include. This would solve the problem. Worked for me.

like image 163
Mohanapriya Avatar answered Nov 15 '22 08:11

Mohanapriya