Disable eager loading for some includes #500
-
At the moment the query builder will try to eager load all parameters passed via the This tries to eager load all includes via the // api/permission-group?include=permission_tree,permissions,users
...
QueryBuilder::for(PermissionGroup::class)
->allowedIncludes(['permission_tree', 'permissions', 'users'])
->findOrFail($id);
... I remove the allowed includes now to stop the eager loading and will handle the validation my self. I expect that this will not try and eager load the include string. However it still tries to eager load all includes: // api/permission-group?include=permission_tree,permissions,users
...
QueryBuilder::for(PermissionGroup::class)
->findOrFail($id);
... There is often a need to allow for includes that are arbitrary data that is defined in the transformer that is not apart of a relation. Fractal/Dingo is what we are using, which seems to be a common combination. Dingo's adapter to Fractal allows you to specify lazy loading includes here on the transformation adapter: https://github.com/dingo/api/blob/master/src/Transformer/Adapter/Fractal.php#L207 Which was merged because of this discussion: dingo/api#1036 Is there a way to disable this that I am missing? This is make or break for us. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
It looks like there is even a TODO for this: https://github.com/spatie/laravel-query-builder/blob/master/src/Concerns/AddsIncludesToQuery.php#L81 |
Beta Was this translation helpful? Give feedback.
-
Hi @cnelson-ma, thanks for opening up a discussion.
This should not happen. There are two different cases:
Can you try to isolate the issue in a failing test case? I'd be happy to fix this issue, once isolated.
This TODO likely exists to allow us to give the user a more meaningful exception if an unknown relation is included. Currently, we let the underlying QueryBuilder check for this, where an |
Beta Was this translation helpful? Give feedback.
Hi @cnelson-ma,
thanks for opening up a discussion.
This should not happen. There are two different cases:
allowedIncludes()
call is made at all -> every include parameter gets ignored silentlyallowedIncludes()
does not contain a user-supplied parameter -> anInvalidIncludeQuery
gets thrown.Can you try to isolate the issue in a failing test case? I'd be happy to fix this issue, once isolated.
This TODO likely exists to allow us to give the user a more meaningful exce…