【问题标题】:Sequelize missing FROM-clause entry for table Postgres为表 Postgres 续集缺少的 FROM 子句条目
【发布时间】:2021-03-02 10:45:33
【问题描述】:

我正在尝试通过包含的 DataPoints 数据为 loc 和 sortOrder 为 2 来过滤我的 DataRow 对象。下面是我正在尝试的查询。我不断收到以下错误。

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

我尝试设置required: trueduplicating: false,但没有成功。我在 DataRows 包括以及 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'],
    ],
  }

【问题讨论】:

  • 你找到解决办法了吗?

标签: node.js database postgresql sequelize.js


【解决方案1】:

在您尝试包含的所有模型上尝试required: trueduplicating: false。这将解决问题。为我工作。

【讨论】:

    【解决方案2】:

    必填和复制设置为 true 和 false 工作,当您尝试急切加载模型并且搜索字段不是唯一的时,问题就出现了,在我的情况下,我能够将我的字段设置为唯一,摆脱设置要求并在急切加载查询中复制属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多