1
我在MongoDB中使用Loopback.io。我无法想象如何使用“包含”过滤器。Loopback.io找到包含
目标是在完成find()或findOne()时将“用户”完全包含在“组”中。我现在得到的是ID中的数组。由于
theuser.json:
{
"name": "theuser",
"plural": "theusers",
"base": "User",
"idInjection": true,
"properties": {
"peerId": {
"type": "string",
"required": false
},
"peerStatus": {
"type": "string",
"required": false
}
},
"validations": [],
"relations": {
"notes": {
"type": "hasMany",
"model": "note",
"foreignKey": "ownerId"
},
"groups": {
"type": "hasMany",
"model": "group",
"foreignKey": "groupId"
}
},
group.json:
{
"name": "group",
"plural": "groups",
"base": "PersistedModel",
"idInjection": true,
"properties": {
"name": {
"type": "string"
}
},
"validations": [],
"relations": {
"host": {
"type": "belongsTo",
"model": "theuser",
"foreignKey": "ownerId"
},
"clients": {
"type": "hasMany",
"model": "theuser",
"foreignKey": "clientId"
}
},
"acls": [],
"methods": []
}
我试图寻找一组像这样:
Group.findOne({
filter: {
where: {"ownerId": 1},
include: {relation: "clients"}
}
}
只是快速评论:“过滤器”是你传递给'findeOne()'的全部东西,所以不需要在中使用它目的。 – jakerella
我明白了,尽管我无法得到这个工作。这可能是外键设置有问题吗?谢谢 – rhymn