You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What problem does this feature proposal attempt to solve?
It'd be really useful to have a directive equivalent of whereHas, to limit the result set of a query based on some restrictions on a nested field. I have a schema set up something like this:
I have a report that is essentially "get all orders that have line items matching a certain filter". What I'd ideally like to be able to do is something like this:
To be clear, this isn't a simple scope or @where on the relation. What I'm after is for the hypothetical @has directive to take all the filters applied to the relation has (in this example, lineItems), and modify the top-level query to add a whereHas with the same set of constraints on that relation:
$query->whereHas($value, function (Builder$query) use ($value) {
$this->enhanceBuilderFromNested($value, $query);
}
That way, any orders that don't have any line items matching the filter would be omitted from the final result set, and all the orders returned would have at least 1 matching line item.
Which possible solutions should be considered?
I looked at @whereHasConditions, but it really only lets you filter based on concrete columns, not any arbitrary conditions created by other directives.
I've also considered inverting this query, AKA querying lineItems and just getting the order field off of that, but then to get a list of orders, I need to flatMap the orders out, and re-match-up the line items, and it's just a bit of a pain for something that feels like it should be doable in GQL.
The text was updated successfully, but these errors were encountered:
loganswartz
changed the title
New directive for using nested field constraints to constrain root query
New directive that mirrors functionality of whereHas for relations (not @whereHasConditions)
Jan 30, 2024
What problem does this feature proposal attempt to solve?
It'd be really useful to have a directive equivalent of
whereHas
, to limit the result set of a query based on some restrictions on a nested field. I have a schema set up something like this:I have a report that is essentially "get all orders that have line items matching a certain filter". What I'd ideally like to be able to do is something like this:
And then on the server side, I'm imagining something like this:
To be clear, this isn't a simple scope or
@where
on the relation. What I'm after is for the hypothetical@has
directive to take all the filters applied to the relationhas
(in this example,lineItems
), and modify the top-level query to add awhereHas
with the same set of constraints on that relation:That way, any orders that don't have any line items matching the filter would be omitted from the final result set, and all the orders returned would have at least 1 matching line item.
Which possible solutions should be considered?
I looked at
@whereHasConditions
, but it really only lets you filter based on concrete columns, not any arbitrary conditions created by other directives.I've also considered inverting this query, AKA querying
lineItems
and just getting theorder
field off of that, but then to get a list of orders, I need to flatMap the orders out, and re-match-up the line items, and it's just a bit of a pain for something that feels like it should be doable in GQL.The text was updated successfully, but these errors were encountered: