我正在尝试使用ember-data和一个node.js后端的Ember应用程序,使用Sequelize.js从 MySQL提供数据. 我的问题: 如果我有一个通过hasMany与Post模型相关联的Comment模型,那么ember-data的预期JSON就像 { "
我的问题:
如果我有一个通过hasMany与Post模型相关联的Comment模型,那么ember-data的预期JSON就像
{
"post": {
"comment_ids": [1, 2, 3]
}
}
使用sequelize在没有昂贵的循环等的情况下查询/生成此JSON的最佳方法是什么?
Comment模型有一个带有post_id的外键.
我去实现它像:// include comments
Post.all({
where: "..",
include: [Comment]
}).success(function(posts) {
// collect IDs
_.each(posts, function(element) {
element["comments"] = _.pluck(element.comments, 'id');
});
});
