loopback-next icon indicating copy to clipboard operation
loopback-next copied to clipboard

@loopback/repository 6.1.4 broke hasManyThrough relations

Open ivanvaccari opened this issue 1 year ago • 4 comments

Describe the bug

After the release of @loopback/repository 6.1.4 about 6 hours ago, my hasManyThrough relations stopped working.

After a quite good amount of hours addressing the issue, got suspicious about this line: https://github.com/loopbackio/loopback-next/blob/master/packages/repository/src/relations/has-many/has-many-through.inclusion-resolver.ts#L271

Please note that i'm using mongodb and both ids, foreign keys are implemented via objectId. In one of the cases, the intersection fails when "targetEntityIds" is represented by a string array, while relatedIds is represented by a ObjectId array. The intersecion fails, returning empty arrays.

Version 6.1.3 of @loopback/repository does not present the problem, i suspect it was introduced via commit https://github.com/loopbackio/loopback-next/commit/34f8201efecfd3973fac354c6ef7765630f72db3

Logs

No response

Additional information

No response

Reproduction

Repository: https://github.com/ivanvaccari/lb4-HasManyThrough-test

Run the following sequence of rest calls:

  1. POST /contact body: { "value": "[email protected]"}

  2. POST /contacts/{previousContactId}/people body: { "name": "John", "age": "wayne"}

  3. GET /contacts/{previousContactId}/people corectly return related models

  4. GET /contacts filter: {where: {id: previousContactId }, include:[{"relation": "people"}]} Does not return correctly related models. Expecting the same output as of point 3.

ivanvaccari avatar Dec 12 '23 21:12 ivanvaccari

@ivanvaccari, thanks for reporting that.

@achrinza @nabdelgadir, the commit mentioned above belongs to https://github.com/loopbackio/loopback-next/pull/8251. any thoughts?

dhmlau avatar Dec 12 '23 22:12 dhmlau

Updated initial post with reproduction example.

ivanvaccari avatar Dec 13 '23 12:12 ivanvaccari

Thanks @ivanvaccari. Would you be interested in submitting a PR to fix the problem?

dhmlau avatar Dec 13 '23 14:12 dhmlau

Are there updates on this topic?

ivanvaccari avatar Jan 17 '24 20:01 ivanvaccari