source/Spiral/ORM/Entities/Relations/ManyToManyRelation.php
protected function loadRelated(): array
    {
        $innerKey = $this->parent->getField($this->key(Record::INNER_KEY));
        if (empty($innerKey)) {
            return [];
        }

        //Work with pre-build query
        $query = $this->createQuery($innerKey);

        //Use custom node to parse data
        $node = new PivotedRootNode(
            $this->schema[Record::RELATION_COLUMNS],
            $this->schema[Record::PIVOT_COLUMNS],
            $this->schema[Record::OUTER_KEY],
            $this->schema[Record::THOUGHT_INNER_KEY],
            $this->schema[Record::THOUGHT_OUTER_KEY]
        );

        $iterator = $query->getIterator();
        foreach ($iterator as $row) {
            //Time to parse some data
            $node->parseRow(0, $row);
        }

        //Memory free
        $iterator->close();

        return $node->getResult();
    }
protected function loadRelated(): array
    {
        $innerKey = $this->parent->getField($this->key(Record::INNER_KEY));
        if (empty($innerKey)) {
            return [];
        }

        //Work with pre-build query
        $query = $this->createQuery($innerKey);

        //Use custom node to parse data
        $node = new PivotedRootNode(
            $this->schema[Record::RELATION_COLUMNS],
            $this->schema[Record::PIVOT_COLUMNS],
            $this->schema[Record::OUTER_KEY],
            $this->schema[Record::THOUGHT_INNER_KEY],
            $this->schema[Record::THOUGHT_OUTER_KEY]
        );

        $iterator = $query->getIterator();
        foreach ($iterator as $row) {
            //Time to parse some data
            $node->parseRow(0, $row);
        }

        //Memory free
        $iterator->close();

        return $node->getResult();
    }
protected function loadRelated ( ) : array { $ innerKey = $ this -> parent -> getField ( $ this -> key ( Record :: INNER_KEY ) ) ; if ( empty ( $ innerKey ) ) { return [ ] ; } //Work with pre-build query $ query = $ this -> createQuery ( $ innerKey ) ; //Use custom node to parse data $ node = new PivotedRootNode ( $ this -> schema [ Record :: RELATION_COLUMNS ] , $ this -> schema [ Record :: PIVOT_COLUMNS ] , $ this -> schema [ Record :: OUTER_KEY ] , $ this -> schema [ Record :: THOUGHT_INNER_KEY ] , $ this -> schema [ Record :: THOUGHT_OUTER_KEY ] ) ; $ iterator = $ query -> getIterator ( ) ; foreach ( $ iterator as $ row ) { //Time to parse some data $ node -> parseRow ( 0 , $ row ) ; } //Memory free $ iterator -> close ( ) ; return $ node -> getResult ( ) ; }
Fetch data from database. Lazy load. Method require a bit of love.

@return array
Fetch data from database . Lazy load . Method require a bit of love .