Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Relations not working #6228

Closed
argupta23 opened this issue Aug 31, 2020 · 2 comments
Closed

Nested Relations not working #6228

argupta23 opened this issue Aug 31, 2020 · 2 comments
Assignees
Labels

Comments

@argupta23
Copy link

Steps to reproduce

There are 3 controllers

  1. User
  2. Devicetempl
  3. Device

Models have the following relations

User.model.ts
@hasmany(() => Device)
devices: Device[];
@hasmany(() => Devicetempl)
devicetempls: Devicetempl[];

Devicetempl.model.ts
@hasmany(() => Device)
devices: Device[];
@belongsTo(() => User)
userId: string;

device.model.ts
@belongsTo(() => Devicetempl)
devicetemplId: string;

using "lb4 relation" I've confirmed that all inclusion resolvers for these relationships are in place and working. The relevant portion of my backend function is below:

async find(@param.path.string('id') id: string>): Promise<(User & UserRelations)[]> { let foundUser = await this.userRepository.find({ include: [ { relation: 'devicetempls', scope: { include: [{relation: 'devices'}], }, }, ], where: {id: id}, }); return foundUser; }

When I test it within explorer I am able to get the associated devicetempl's associated with this user, but it does not contain the devices associated with the devicetempl.

Looking into the mongodb debug log, I can see the result of the query does contain the devices associated with the devicetempl, but for some reason they are not contained in the explorer output.

loopback:connector:mongodb all Device { fields: [ 'deviceid' ], where: {} } null [ { _id: 5f3c7d49d1b72df053895ee6, deviceid: '1234567' }, { _id: 5f3d6551c3f1126e385867db, deviceid: 'abcdef' } ]

I've confirmed that my formatting looks correct using issues #3453 and #4644, as well as reading the bottom section of these master docs:
https://github.com/strongloop/loopback-next/blob/master/docs/site/HasMany-relation.md#query-multiple-relations
.Additionally, a previous StackOverflow question (48391685) seems to address this formatting and everything looks to match.

Is there a possible bug between Loopback 4 and MongoDB nested HasMany queries or does anyone else possibly spot anything else wrong with what I am doing?

Thank you in advance for the help!

Additional information

npm ls --prod --depth 0 | grep loopback
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── @loopback/[email protected]
├── [email protected]

@argupta23 argupta23 added the bug label Aug 31, 2020
@dhmlau
Copy link
Member

dhmlau commented Sep 5, 2020

@agnes512, could you please take a look? Thanks.

@argupta23
Copy link
Author

@dhmlau

Earlier last week I brought this up on the Slack channel and with help from Agnes was able to resolve the issue.

Thanks again for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants