sequelize.js

Sequelize 4.3.2 n:m (many-to-many) association: Unhandled rejection SequelizeEagerLoadingError

别等时光非礼了梦想. 提交于 2020-08-24 08:19:42
问题 I have 3 models: User, Project, UserProject: module.exports = function (sequelize, DataTypes) { var User = sequelize.define('User', { title: DataTypes.STRING, description: DataTypes.STRING }, { classMethods: { associate: function (models) { User.belongsToMany(models.Project, { through: 'UserProject', foreignKey: 'userId' }) } }, freezeTableName: true }) return User } module.exports = function (sequelize, DataTypes) { var Project = sequelize.define('Project', { title: DataTypes.STRING,

Sort sequelize.js query by date

天大地大妈咪最大 提交于 2020-08-22 07:14:40
问题 Post .findAll({where: {tag: 'news'}, limit: 10}) .success(function(result) { ... }) How to insert the condition of sorting by date in my query with not using sequelize.query like .findAll({ limit: 10, sort: [updatedAt, descending]}) 回答1: Here's the syntax: Post.findAll({ limit: 10, order: '"updatedAt" DESC' }) Here are more examples from the official documentation. 回答2: @dankohn is correct and that will work but it is safer to use the following: Post.findAll({ limit: 10, order: [['updatedAt',