-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Hi,
I'm wondering if the 'limit' param works if added to the scope of nested relations, to limit the number of items of a hasMany relation. I have a strange behaviour in the response.
I have a BusinessPartner model with hasMany relation to Addresses
@hasMany(() => BuspartnerAddress, {keyTo: 'clientId', name: 'addresses'})
addresses: BuspartnerAddress[];
I want to get the businessPartners with only the first address for each one. My filter param looks like
{
"order": ["name ASC"],
"where": {
"bustype": "CUSTOMER"
},
"include": [
{
"relation": "addresses",
"scope": {
"skip": 0,
"limit": 1,
"where": {
"deleted": false
}
}
}
]
}
The where clause in the scope of the include works well, but the limit: 1 param returns the address for only one businessPartner, not one for each businessPartner. If I increase the value of the limit, e.g. 10, the response returns max 10 address, differently distribuited on the businessPartners.
It looks like the query on the related models was performed only once and not for each 'parent' instance (businessPartner).
Am I wrong in something? Is this the intended behaviour?
I'm using a postgresql connector and this is my ecosystem (Nodejs v12.16.2 npm v6.14.4 - Postresql 12)
├── @loopback/authentication@4.2.3
├── @loopback/boot@2.2.0
├── @loopback/context@3.7.0
├── @loopback/core@2.5.0
├── @loopback/cron@0.2.7
├── @loopback/openapi-v3@3.3.1
├── @loopback/repository@2.4.0
├── @loopback/rest@4.0.0
├── @loopback/rest-explorer@2.2.0
├── @loopback/service-proxy@2.2.0
├── loopback-connector-postgresql@3.9.1
├── loopback-connector-rest@3.7.0
Thank you very much
PS: maybe related to #3453