[英]Loopback where filter not working inside include
I have this filter written that i am passing to my endpoint written in Loopbackjs.我写了这个过滤器,我将传递给我用 Loopbackjs 编写的端点。
const filter = {
where: { status: { neq: "processed" } },
include: [
{ relation: "vendor", scope: { fields: ["id", "name"] } },
{
relation: "pickupLocation",
scope: { where: { cityId: "5ee134da0138634c27a6e1dd" } },
},
],
limit: 200,
skip: 0
};
return this.http.get<IPickupRequest[]>(
`${environment.url}/PickupRequests?filter=${encodeURIComponent(
JSON.stringify(filter)
)}`
);
The pickupRequest
collection contains a belongsTo
relation to pickupLocation collection. pickupRequest
集合包含一个与pickupLocation 集合的belongsTo
关系。 The pickupLocation collection contains a property called cityId
on which i am trying to apply a where clause but it does not work. PickLocation 集合包含一个名为
cityId
的属性,我试图在该属性上应用 where 子句,但它不起作用。 Moreover I also want to get the fields of pickupLocation too inside the pickupRequest object so that i cna use them in my table.此外,我还想在pickupRequest 对象中获取pickupLocation 的字段,以便我可以在我的表中使用它们。 The simple include works perfectly and shows the data as desired but when
where
clause is applied it just doesn't work and also shows only pickupRequest object but does not include pickupLocation data inside it.简单的 include 工作完美,并根据需要显示数据,但是当应用
where
子句时where
它不起作用,并且只显示 pickRequest 对象,但不包含其中的 pickerLocation 数据。 Moreover since i am using pagination I need it to return me exactly 200 records each time.此外,由于我使用分页,我需要它每次准确返回 200 条记录。 Am i doing something wrong?
难道我做错了什么? What is the exact issue here?
这里的确切问题是什么? I am using Loopback 3
我正在使用环回 3
Here, you are expecting that where
filter applied on the pickupLocation
relation would act something similar to SQL's inner join.在这里,您期望在
pickupLocation
关系上应用where
过滤器的行为类似于SQL 的内部联接。 However, in loopback, whenever you do an include
in the query, the framework internally makes two separate queries on collections or tables of each of those models and combine them;但是,在环回中,每当您在查询中执行
include
时,框架在内部对每个模型的集合或表进行两个单独的查询并将它们组合起来; effectively making it work like SQL's left outer join.有效地使它像 SQL 的左外连接一样工作。 So, in the above query
PickupRequest
list will have all object, irrespective of where filter on pickupLocation
model.因此,在上面的查询
PickupRequest
列表中将包含所有对象,而不管pickupLocation
模型上的过滤器在pickupLocation
。 The pickupLocation
relation would be present only in those PickupRequest
records where cityId = "5ee134da0138634c27a6e1dd"
and remaining places, the relation would be an null
object. pickupLocation
关系只会出现在cityId = "5ee134da0138634c27a6e1dd"
和剩余地点的那些PickupRequest
记录中,该关系将是一个null
对象。
To overcome this problem, I would say, make your primary query on pickupLocation
model as per the { cityId: "5ee134da0138634c27a6e1dd" }
where filter and do an include of PickupRequest
model.为了克服这个问题,我想说,根据
{ cityId: "5ee134da0138634c27a6e1dd" }
对pickupLocation
模型进行主要查询,其中过滤器并包含PickupRequest
模型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.