我定义了如下两个模型,我需要做的是检索属于活跃合作伙伴 (partner.status=1) 的唯一社区,我可以像这样检索分组的社区
Locations.find({groupBy: [ 'neighborhood' ],sum['id']}, function(err,locations){});
然后匹配检索到的事件合作伙伴列表或向后匹配(即首先获取事件合作伙伴及其每个合作伙伴的位置,并在验证它们不在数组中后将它们推送到数组中)或仅通过自定义 sql 查询(我试图远离) 但是...我想知道是否有某种方法可以使用 ORM 来完成它,因为我已经看到 model.find().populate('model') 不接受超出的参数所需的模型而不是 find 方法中的 where 接受外键条件。
Partner:{
attributes:{
businessName:{
type:'string'
},
status:{
type:'INT'
}
locations:{
model:'Locations'
via:'partner_id'
}
}
}
Locations:{
attributes:{
partner_id:{
model:'Partners',
type:'INT'
},
neighborhood:{
type:'STRING'
}
}
}
提前致谢!
最佳答案
这是你要找的吗?
Locations.find({where: {value1: key1}})
.populate('partners', {where: {value2: key2}})
.exec(function(err, locations){
// Now you've got what you need
});
P/S:请查看 GitHub 上的 SailsJS v0.10.x 文档。我个人使用这个:https://github.com/balderdashy/sails-docs/tree/0.10 虽然这些文件不是最新的:-)
关于javascript - sailsjs Waterline ORM 中的外键条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24502633/