查询 3 深度关系环回
Query 3 Deep Relationship Loopback
我正在尝试按照此处的说明和示例进行嵌套查询:
https://docs.strongloop.com/display/public/LB/Include+filter
https://github.com/strongloop/loopback/issues/735
但它没有像我预期的那样工作。我有一个帐户,可以有很多分支机构,可以有很多事件、风险评估和索赔。我已经为分支机构创建了一个自定义端点来查询相关的事件、风险评估和索赔,但我无法从帐户级别获取信息。
这是分支的工作代码:
Branch.find({
where: {
id: id
},
include: [
{
relation: 'incidents',
scope: {
where: {
incidentDate: {
between: [
beginDate,
today
]
}
}
}
},
{ relation: 'riskAssessments' },
{ relation: 'claims' }
}, function (err, obj) {
if (err) return cb(err);
cb(null, obj);
});
这是我希望用于帐户的代码:
Account.find({
where: {
id: id,
},
include: {
relation: 'branches',
scope: {
include: [
{
relation: 'incidents',
scope: {
where: {
incidentDate: {
between: [
beginDate,
today
]
}
}
}
},
{ relation: 'riskAssessments' },
{ relation: 'claims' }
]
}
}
}, function (err, obj) {
if (err) return cb(err);
cb(null, obj);
});
但是,这只给我帐户和一个空的分支数组。如果我 运行 使用此代码:
Account.find({
where: {
id: id,
},
include: {
relation: 'branches',
}
},function (err, obj) {
if (err) return cb(err);
cb(null, obj);
});
它给了我相关分支机构的帐户。每当我添加
scope: {
include: {
relations: 'riskAssessments',
}
}
它不起作用,returns 空的 Branch 数组。我可以在范围内添加其他参数,如字段、位置等,它们按预期工作,就在我添加 include 时。
我 运行 遇到的问题与可以在此处找到的错误有关:https://github.com/strongloop/loopback/issues/2356
简而言之,确保您的 none 个 ID 为 0,否则您将 运行 陷入此问题。
我正在尝试按照此处的说明和示例进行嵌套查询: https://docs.strongloop.com/display/public/LB/Include+filter https://github.com/strongloop/loopback/issues/735
但它没有像我预期的那样工作。我有一个帐户,可以有很多分支机构,可以有很多事件、风险评估和索赔。我已经为分支机构创建了一个自定义端点来查询相关的事件、风险评估和索赔,但我无法从帐户级别获取信息。
这是分支的工作代码:
Branch.find({
where: {
id: id
},
include: [
{
relation: 'incidents',
scope: {
where: {
incidentDate: {
between: [
beginDate,
today
]
}
}
}
},
{ relation: 'riskAssessments' },
{ relation: 'claims' }
}, function (err, obj) {
if (err) return cb(err);
cb(null, obj);
});
这是我希望用于帐户的代码:
Account.find({
where: {
id: id,
},
include: {
relation: 'branches',
scope: {
include: [
{
relation: 'incidents',
scope: {
where: {
incidentDate: {
between: [
beginDate,
today
]
}
}
}
},
{ relation: 'riskAssessments' },
{ relation: 'claims' }
]
}
}
}, function (err, obj) {
if (err) return cb(err);
cb(null, obj);
});
但是,这只给我帐户和一个空的分支数组。如果我 运行 使用此代码:
Account.find({
where: {
id: id,
},
include: {
relation: 'branches',
}
},function (err, obj) {
if (err) return cb(err);
cb(null, obj);
});
它给了我相关分支机构的帐户。每当我添加
scope: {
include: {
relations: 'riskAssessments',
}
}
它不起作用,returns 空的 Branch 数组。我可以在范围内添加其他参数,如字段、位置等,它们按预期工作,就在我添加 include 时。
我 运行 遇到的问题与可以在此处找到的错误有关:https://github.com/strongloop/loopback/issues/2356
简而言之,确保您的 none 个 ID 为 0,否则您将 运行 陷入此问题。