Solution to filter nested multiple content links

I know this subject has already been talked and some solutions have been provided but I would like to purpose one that can be integrated to the core.
It’s a one line solution and for the specific purpose of multiple content links!

I’ve ben using it without issues with MongoLite but I believe it works with others.
I cant apply it as an addon because it belongs on the core and addon solutions (post DB retrieval) seems hacky.

if (count($a) && array_key_exists('_model', $a[0])) $a = array_column($a, '_id');

This line must be added to the ‘$has’ switch option on the /lib/MongoLite/UtilArrayQuery.php

Final result like this:

case '$has' :
    if (\is_array($b))
        throw new \InvalidArgumentException('Invalid argument for $has array not supported');
    if (!\is_array($a)) $a = @\json_decode($a, true) ?  : [];
    if (count($a) && array_key_exists('_model', $a[0]))
        $a = array_column($a, '_id');
    $r = \in_array($b, $a);
    break;

To use it, using blog examples, apply a filter on posts collection with {“categories”:{“$has”:“<category_id>”}}", considering categories is a Collection Link with multiple option active.

I hope @artur can check it out, review it and maybe make it available for everyone.

It’s been an issue on MongoLite usage and it can be a closed chapter!

Kind regards,
Miguel Pereira