Eagerload additional relations if a particular relation is included in the query #468
-
So, I have a 2 relations added to my Let's say for example $query->allowedIncludes(['products','saleableProducts']); If the request includes How do I go about doing this? Is there a way to check if the underlying query has a specific Or can I do $query->allowedIncludes([
'products',
'saleableProducts.media',
'saleableProducts.supplier',
'saleableProducts.shops'
]); and when |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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 For your second question:
No, you have to manually add them to the URL as well: Good luck! |
Beta Was this translation helpful? Give feedback.
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:
No, you have to manually add them to the URL as well:
GET /shops?include=saleablePr…