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

Include related models with a custom scope #3453

Open
bajtos opened this issue Jul 26, 2019 · 7 comments

Comments

@bajtos
Copy link
Member

@bajtos bajtos commented Jul 26, 2019

Besides specifying the relation name to include, it's also possible to specify additional scope constraints:

  • custom order, limit, skip and fields
  • additional scope.where constraint

For example, the following filter will include only the first active product:

filter.include = [{
  relation: 'products',
  scope: {
    where: {active: true},
    limit: 1
  }
}

The initial version of Inclusion does not support custom scopes. In this story, we should improve findByForeignKeys function to support additional scope constraints.

LB3 test suite: loopback-datasource-juggler/test/include.test.js#L247-L253)

See also #3387

Acceptance criteria

TBD - will be filled by the team.

@luncht1me

This comment has been minimized.

Copy link

@luncht1me luncht1me commented Oct 8, 2019

Was trying to do a filter query

include: [
{ relation: 'relatedModel', scope: { include:[{ relation: 'relatedRelatedModel' }] } },
]

but got shut down by 'scope not supported' error. I see it's written in the type definitions though, is this just a bad package version on my part perhaps? Or is scope within a relation actually not hashed out completely yet?

How should we be handling nested relationships? ie: I have a source base model w/ a hasmany to a mapping model, which has a hasmany mapping to another target model. Should I just custom spin a controller method to do it all manually for now? It would be great to just use the inclusion resolver like this.

edit ---- right I see in the source it's not implemented, my bad. I'll spin up a custom method to link it all together for now.

@kundk-ckret

This comment has been minimized.

Copy link

@kundk-ckret kundk-ckret commented Oct 18, 2019

I have the same issue and need to query nested relations...
Is there no way atm to do this automatically? I have a tree structure and don't want to query for each node seperatly :(

@st119848

This comment has been minimized.

Copy link

@st119848 st119848 commented Oct 19, 2019

i need inclusion in inclusion toooo. @luncht1me

@theophane-girard

This comment has been minimized.

Copy link

@theophane-girard theophane-girard commented Oct 20, 2019

Me too ! :)

@tipsypastels

This comment has been minimized.

Copy link

@tipsypastels tipsypastels commented Nov 8, 2019

Would really like to see this added.

@ericalves

This comment has been minimized.

Copy link

@ericalves ericalves commented Nov 8, 2019

Is too hard use lb4 without nested include relations.. mostly if you came from lb3..

@ericalves

This comment has been minimized.

Copy link

@ericalves ericalves commented Nov 8, 2019

Was trying to do a filter query

include: [
{ relation: 'relatedModel', scope: { include:[{ relation: 'relatedRelatedModel' }] } },
]

but got shut down by 'scope not supported' error. I see it's written in the type definitions though, is this just a bad package version on my part perhaps? Or is scope within a relation actually not hashed out completely yet?

How should we be handling nested relationships? ie: I have a source base model w/ a hasmany to a mapping model, which has a hasmany mapping to another target model. Should I just custom spin a controller method to do it all manually for now? It would be great to just use the inclusion resolver like this.

edit ---- right I see in the source it's not implemented, my bad. I'll spin up a custom method to link it all together for now.

Do you can show to us what you did to get around this problem?

@dhmlau dhmlau added the 2020Q1 label Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
You can’t perform that action at this time.