select查询在水-postgresql的.populate()中无效。
Model.find(query).populate(assoc.alias,{select:['field1','field2']});这并不适用于水-postgresql适配器。
这是不支持的,还是我犯了什么错误?
发布于 2015-07-08 12:07:14
select在.populate()中不受支持。你可以看到这个github问题。在填充中,select当前无法工作。
这是一个特性请求,也是一个悬而未决的问题。希望在下一个版本中,水线团队将引入这个特性。
发布于 2015-11-26 23:36:27
因为没有正式的方法去做,所以我做了一些改变来达到这个目的。也许这不是最好的方法,但有效。
User.find({ belongs_to: user.id })
.populate('person_id')
.exec(function findCB (err, usersFound)
{
console.log(usersFound[0].toJSON())
if (err)
{
return res.json(401, {error: err});
}
if (usersFound.length == 0)
{
return res.json(200, {message: 'No user asigned'});
}
else
{
// An array to store all the final user objects
var asignedArray = [];
for (index in usersFound)
{
var myObj = {},
key,
value;
// Object in format {key: value}
myObj['id'] = usersFound[index].id;
myObj['fullname'] = usersFound[index].person_id.first_name + ' ' +
usersFound[index].person_id.second_name + ' ' +
usersFound[index].person_id.last_name;
myObj['email'] = usersFound[index].email;
myObj['job'] = usersFound[index].person_id.job;
myObj['permission_level'] = usersFound[index].permission_level;
// Adding the object to the main array
asignedArray.push(myObj);
}
return res.json(200, {
users: asignedArray
});
}
});我希望它能对你有用。
https://stackoverflow.com/questions/31292018
复制相似问题