Remove entries from object

After a complex find(), I want to remove some entries that match a parameter that was not available in the find method.
So I have a list (query object) of $folders with id, name etc.
I tried unset($folder) without success (no error)

Which do you really have, a query object, or a list? Those are two very different things, though you can iterate over both.

Sorry for the “list” term.
It’s a query object.

You’ll need to provide more specifics if you want a specific solution, but from what you’ve said so far, if you have a query object, you can just add more conditions to it before you iterate or otherwise execute it. If for some reason that can’t work, then I’d suggest maybe make a collection from the results, then one of match, filter or reject to get to just what results you want.

More details :
The query extracts images or documents from folders. (easy)
Folders have sub-folders, sub-sub-folders etc. (still easy)
But sometimes, the top folder is not allowed to some users ($role = n)
Query :
($fichiers = $files in French)
$fichiers = $this->Fichiers->find()
->where(function ($exp) use ($term) {
$orConditions = $exp->or_(function ($or) use ($term) {
return $or->like(‘Fichiers.name’, “%$term%”)
->like(‘Fichiers.slug’, “%$term%”)
->like(‘Fichiers.keywords’, “%$term%”)
->like(‘Fichiers.description’, “%$term%”);
});
return $exp
->gte(‘dossier_id’, 2)
->add($orConditions);
})
->contain([‘Dossiers’])
->limit(100)
->all()
;

Can you write a SQL query that includes the user role check? Or is it not something that the database can do for you?

Probably not because I have to get the ids of the folders that cannot be read and particularly the top level folder. And this is done per user.
In the DB, Users have a role.
If role is 3 or 4, there is another column called access in which I store a json array that contains the ids of forbidden folders.
This is meant for students and interns who are not allowed to read confidential or classified information.
Another problem is that I have to know the id of the top folder (Tree behavior) to get the whole path.
I think the only solution is to filter the result object after the search method.

So if I cannot do it directly, maybe I could make an array of the query object and filter it with unset or array_splice.

If it can’t be done in SQL, then the collection functions I mentioned are probably the way to go.

Ok.
Thank you again. I’ll have a look at these collections (never used this before)