Loopback.io 查找包含
Loopback.io find with include
我正在使用 Loopback.io,MongoDB。我不知道如何使用 "include" 过滤器。
目标是在完成 find() 或 findOne() 后将 "theuser" 完全包含在 "group" 中。我现在得到的只是数组中的 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"}
}
}
Group.findOne({
where: {
ownerId: 1
},
include: 'clients'
}, cb);
我正在使用 Loopback.io,MongoDB。我不知道如何使用 "include" 过滤器。
目标是在完成 find() 或 findOne() 后将 "theuser" 完全包含在 "group" 中。我现在得到的只是数组中的 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"}
}
}
Group.findOne({
where: {
ownerId: 1
},
include: 'clients'
}, cb);