L
L
Lucius Mooning2018-07-24 09:46:44
Laravel
Lucius Mooning, 2018-07-24 09:46:44

How to solve the out-of-memory error when executing such a query?

Good afternoon!
The goal is to get a list of all permissions for a given model instance(s).
I make such a command in the controller method and I get an out of memory error.

BigTask::where('id', $id)->with(['modules.groups.permissions' => function ($q) use (&$permissions) {
     $permissions = $q->get()->unique();
}])->first();

BigTask models and corresponding relation-models modules, groups, have LONGBLOB type fields. I suspect that when these fields are executed, everyone is trying to dive.
In this regard, the questions are: 1) is it possible to load only certain fields, and not all); 2) or is there another way to get the list of $permissions

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yan-s, 2018-07-24
@Yan-s

Start by reading the documentation https://laravel.com/docs/queries#selects

BigTask::where('id', $id)->with(['modules.groups.permissions' => function ($q) use (&$permissions) {
     $permissions = $q->get()->unique(); // <--- что это вы тут делаете?
}])->first();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question