从关系中select特定的字段
我正在用waterline(使用mysql适配器)在node.js(sails)上构build一个webapp。
我已经设法让关系像这样工作:
//Post.js attributes post_statistics: { collection: 'postStatistics', via: 'post' }
我可以很容易地find与该行的关系logging:
var query = {user:userId}; // Just filtering by the user query.is_public = Post.POSTS_ONLY_ACTIVE; // Only showing active posts, boolean query.select = ['id','title','content']; // id is only needed for me to get the join working Post.find(query).populate('post_statistics').exec(cb);
一切工作正常,但我只需要从post_statisticsselect特定的字段。 这似乎没有做任何事情,但是,我希望它的工作:
Post.find(query).populate('post_statistics',{select:['post','user','id']}).exec(cb);
将字段名称添加到初始select更糟,因为这些字段已经定位到发布表。
任何理智的方法,使这项工作,或者我将不得不写整个查询?
目前.populate({ assoc, select: [] })
在水线中不受支持,更多细节请参见https://github.com/balderdashy/waterline/issues/919 。
一种可能的select是通过.query()
( docs )运行SQL查询。
另一种方法是将修补程序提交.populate({ assoc, select: [] })
线添加对.populate({ assoc, select: [] })
。