当我在我的模型中添加 Sequelize 的关联时,我遇到了错误“...用不是 Sequelize.Model 的子类的东西调用”,它称为错误,即我所说的不是 Sequelize 模型
E:...\Projects\WebApps\hr1\hr1\node_modules\sequelize\lib\associations\mixin.js:81
throw new Error(this.name + '.' + Utils.lowercaseFirst(Type.toString()) + ' called with something that\'s not a subclass of Sequelize.Model');
^
Error: user_employee_tm.class BelongsTo extends Association {
constructor(source, target, options) {
super(source, target, options);
this.associationType = 'BelongsTo';
this.isSingleAssociation = true;
this.foreignKeyAttribute = {};
if (this.as) {
this.isAliased = true;
this.options.name = {
singular: this.as
};
} else {
this.as = this.target.options.name.singular;
this.options.name = this.target.options.name;
}
if (_.isObject(this.options.foreignKey)) {
this.foreignKeyAttribute = this.options.foreignKey;
this.foreignKey = this.foreignKeyAttribute.name …Run Code Online (Sandbox Code Playgroud) 我在使用排序显示数据时遇到问题.这是我的查询,
Activity.find({"user_id": sesUser._id}, {}, {offset: 0, limit : 5, sort:{createdAt:1}}, function (e,a){
...
});
Run Code Online (Sandbox Code Playgroud)
我有关于252长度的数据,我的最新数据是2015年6月9日.如果我使用此查询我只从2015年6月5日/上周数据获得数据而不是获取最新数据,但如果我不使用排序,则最新数据出现了.
我在下面使用过这个查询但结果却是一样的.
Activity.find({"user_id" : sesUser._id}).sort("createdAt").exec(function(err,a){
...
});
Run Code Online (Sandbox Code Playgroud)
有帮助吗?我正在使用Mongoose v3
- 编辑 - 这是我的活动架构/模型
var mongoose = require('mongoose');
var Activity = mongoose.Schema({
sender_id : {type: String, required: true },
user_id : {type: String, required: true },
product_id : {type: String, default : "" },
type : {type: String, required: true },
createdAt : {type: String, default : new Date()}
});
module.exports = mongoose.model('Activity', Activity);
Run Code Online (Sandbox Code Playgroud)