Reputation: 14179
I have created the following model in sequelize:
export function initialize(sequelize: Sequelize.Sequelize, dataTypes: Sequelize.DataTypes): SalesPerson.Model {
var salesPersonModel = sequelize.define<SalesPerson, SalesPerson.Pojo>('salesPerson', {
ownerId: { type: dataTypes.STRING, allowNull: false, field: 'owner_id' },
firstName: { type: dataTypes.STRING, allowNull: false, field: 'first_name' },
lastName: { type: dataTypes.STRING, allowNull: false, field: 'last_name' },
email: { type: dataTypes.STRING, allowNull: false }
}, {
underscored: true,
tableName: 'sales_persons'
});
salesPersonModel.removeAttribute('id');
return salesPersonModel;
}
after starting sequelize.sync()
the table is correctly created. the problem is that when I make a query like this:
db.SalesPerson.find({ limit: 1, order: [['updated_at DESC']] })...
I got the following error:
Unhandled rejection SequelizeDatabaseError: ER_BAD_FIELD_ERROR: Unknown column 'salesPerson.updated_at DESC' in 'order clause'
and this has not sense because I see in the database the column so should be something related with sequelize
Upvotes: 0
Views: 1067
Reputation: 46323
That's not how the syntax works. You need to separate the column name from the direction:
db.SalesPerson.find({ limit: 1, order: [['updated_at', 'DESC']] })...
Upvotes: 1