-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Postgres Eager loading SQL syntax error. #1589
Copy link
Copy link
Closed
Labels
type: bugDEPRECATED: replace with the "bug" issue typeDEPRECATED: replace with the "bug" issue type
Description
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;
};Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type: bugDEPRECATED: replace with the "bug" issue typeDEPRECATED: replace with the "bug" issue type