Webiny\Component\Entity\Attribute\Many2ManyAttribute::load PHP Method

load() protected method

Load many2many attribute value (prepares MongoCursor, lazy loads data)
protected load ( ) : EntityCollection
return Webiny\Component\Entity\EntityCollection
    protected function load()
    {
        $firstClassName = $this->extractClassName($this->getParentEntity());
        $secondClassName = $this->extractClassName($this->getEntity());
        // Select related IDs from aggregation table
        $query = [$firstClassName => $this->getParentEntity()->id];
        $relatedObjects = Entity::getInstance()->getDatabase()->find($this->intermediateCollection, $query, [$secondClassName => 1]);
        $relatedIds = [];
        foreach ($relatedObjects as $rObject) {
            $relatedIds[] = $rObject[$secondClassName];
        }
        // Find all related entities using $relatedIds
        $callable = [$this->getEntity(), 'find'];
        return call_user_func_array($callable, [['id' => ['$in' => $relatedIds]]]);
    }