Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 从关系中选择特定字段_Node.js_Waterline - Fatal编程技术网

Node.js 从关系中选择特定字段

Node.js 从关系中选择特定字段,node.js,waterline,Node.js,Waterline,我正在使用waterline(使用mysql适配器)在node.js(sails)上构建一个webapp 我已经成功地让人际关系像这样运作: //Post.js attributes post_statistics: { collection: 'postStatistics', via: 'post' } 我可以很容易地找到与该行的关系记录: var query = {user:userId}; // Just filtering by the

我正在使用waterline(使用mysql适配器)在node.js(sails)上构建一个webapp

我已经成功地让人际关系像这样运作:

//Post.js attributes
    post_statistics: {
        collection: 'postStatistics',
        via: 'post'
    }
我可以很容易地找到与该行的关系记录:

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_统计中选择特定字段。 不过,这似乎没有任何作用,我希望它能起作用:

Post.find(query).populate('post_statistics',{select:['post','user','id']}).exec(cb);
将字段名添加到初始选择中更糟糕,因为字段已经指向post

是否有任何合理的方法来实现这一点,或者我必须编写整个查询?

当前
。水线中不支持填充({assoc,select:[]})
,有关详细信息,请参阅

一种可能的替代方法是通过
.query()
()运行SQL查询


另一个方法是提交一个补丁来添加对
.populate({assoc,select:[]})

的支持,谢谢您的回复。实际上,我做了一些研究,waterline似乎确实支持select,它在磁盘适配器上的效果非常好。但我尝试将其切换到mysql sails,但它在那里不起作用。因此,我想问题一定出在mysql sails上。无论如何,我会在线程上对github做更多的评论。不客气。好吧,它不是在NOR上,所以我不认为它是“官方支持的”。换句话说,在给定的适配器中,您可能会很幸运,但由于它不受明确支持,后续的更改可能会无意中破坏这种行为。