sequelize 1.6 在更新日志中有以下内容:
[FEATURE] 为 find 和 findAll 添加关联预取
问题是如何?
我定义了以下模型:
var self = {
Medium: client.define("Medium", {
name: Sequelize.STRING,
description: Sequelize.TEXT
},
User: client.define("User", {
firstName: Sequelize.STRING,
lastName: Sequelize.STRING,
email: Sequelize.STRING,
aboutArt: Sequelize.TEXT,
bio: Sequelize.TEXT,
password: Sequelize.STRING,
description: Sequelize.TEXT
}
};
self.User.hasMany(self.Medium, { as: 'Media' });
self.Medium.hasMany(self.User);
for(var key in self){
var model = self[key];
model.sync();
}
稍后当我获取这样的用户时:
User.find(id)
.success(function(record) {
//record has no media!
})
User 实例没有列表媒体。我如何自动获取关联?