Skip to content

Eagerload additional relations if a particular relation is included in the query #468

You must be logged in to vote

Hi @abishekrsrikaanth! I'm not sure if there's an easy way to conditionally load relationships based on another relation being loaded in the same query.

Under the hood the query builder simply adds the relations you request the an Eloquent query. So for ?include=products we run $query->with('products'). This means there's no easy way to define a conditional include at the time of the request. There's ways around this but nothing supported by this package.

For your second question:

and when saleableProducts is included in the request, then subsequently all the relations mentioned are automatically loaded?

No, you have to manually add them to the URL as well: GET /shops?include=saleablePr…

Replies: 1 comment

You must be logged in to vote
0 replies
Answer selected by AlexVanderbist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #468 on June 17, 2020 07:33.