Skip to content

Postgres Eager loading SQL syntax error. #1589

@vjames19

Description

@vjames19

When I execute db.GoesVariable.findAll({include: [db.GoesMap]});

This is what I get:

Executing (default): SELECT GoesVariables.*, GoesMaps.variableName AS GoesMaps.variableName, GoesMaps.imagePath AS GoesMaps.imagePath, GoesMaps.dataDate AS GoesMaps.dataDate, GoesMaps.createdAt AS GoesMaps.createdAt, GoesMaps.updatedAt AS GoesMaps.updatedAt FROM GoesVariables LEFT OUTER JOIN GoesMaps AS GoesMaps ON GoesVariables.variableName = GoesMaps.variableName;
{ [error: syntax error at or near "."]
  name: 'error',
  length: 83,
  severity: 'ERROR',
  code: '42601',
  detail: undefined,
  hint: undefined,
  position: '58',
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  file: 'scan.l',
  line: '1053',
  routine: 'scanner_yyerror',

Is there a way to fix this?

The following has my model definitions
Model: GoesVariable

'use strict';

module.exports = function(sequelize, DataTypes) {

  var GoesVariable = sequelize.define('GoesVariable', {
    variableName: {
      type: DataTypes.STRING,
      primaryKey: true
    },
    description: {
      type: DataTypes.TEXT,
      allowNull: true,
      validate: {
        notEmpty: true
      }
    }
  }, {
    classMethods: {
      associate: function(models) {
        GoesVariable.hasMany(models.GoesMap, {foreignKey: 'variableName'});
        GoesVariable.hasMany(models.GoesData, {foreignKey: 'variableName'});
      }
    }
  });

  return GoesVariable;
};

Model: GoesMap

'use strict';

module.exports = function(sequelize, DataTypes) {
  var GoesMap = sequelize.define('GoesMap', {
    variableName: {
      type: DataTypes.STRING,
      references: 'GoesVariables',
      referencesKey: 'variableName',
      primaryKey: true
    },
    imagePath: {
      type: DataTypes.STRING,
      primaryKey: true,
      validate: {
        notEmpty: true
      }
    },
    dataDate: {
      type: DataTypes.DATE,
      primaryKey: true
    },
    createdAt: {
      type: DataTypes.DATE,
      defaultValue: DataTypes.NOW,
      primaryKey: true
    },
  }, {
    classMethods: {
      associate: function(models) {
        GoesMap.belongsTo(models.GoesVariable, {foreignKey: 'variableName'});
      },
      getLatest: function(variableName) {
        return GoesMap.find({
          where: {
            variableName: variableName
          },
          order: 'dataDate desc'
        });
      },
      getMapsBetween: function(variableName,startDate, endDate) {
        return GoesMap.findAll({
          where: {
            variableName: variableName,
            dataDate: {
              between: [startDate, endDate]
            }
          }
        });
      }
    }
  });

  return GoesMap;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugDEPRECATED: replace with the "bug" issue type

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions