public function with(string $relation) : self
    {
        $this->qiterator = null;
        $parts = explode('.', $relation);
        $table = $this->definition;
        array_reduce(
            $parts,
            function ($carry, $item) use (&$table) {
                $relation = $table->getRelation($item);
                if (!$relation) {
                    throw new DBException('Invalid relation name');
                }
                $name = $carry ? $carry . static::SEP . $item : $item;
                $this->withr[$name] = [ $relation, $carry ?? $table->getName() ];
                $table = $relation->table;
                return $name;
            }
        );
        return $this;
    }
public function with(string $relation) : self
    {
        $this->qiterator = null;
        $parts = explode('.', $relation);
        $table = $this->definition;
        array_reduce(
            $parts,
            function ($carry, $item) use (&$table) {
                $relation = $table->getRelation($item);
                if (!$relation) {
                    throw new DBException('Invalid relation name');
                }
                $name = $carry ? $carry . static::SEP . $item : $item;
                $this->withr[$name] = [ $relation, $carry ?? $table->getName() ];
                $table = $relation->table;
                return $name;
            }
        );
        return $this;
    }
public function with ( string $ relation ) : self { $ this -> qiterator = null ; $ parts = explode ( '.' , $ relation ) ; $ table = $ this -> definition ; array_reduce ( $ parts , function ( $ carry , $ item ) use ( & $ table ) { $ relation = $ table -> getRelation ( $ item ) ; if ( ! $ relation ) { throw new DBException ( 'Invalid relation name' ) ; } $ name = $ carry ? $ carry . static :: SEP . $ item : $ item ; $ this -> withr [ $ name ] = [ $ relation , $ carry ?? $ table -> getName ( ) ] ; $ table = $ relation -> table ; return $ name ; } ) ; return $ this ; }
Solve the n+1 queries problem by prefetching a relation by name
@param  string $relation the relation name to fetch along with the data
@return $this
Solve the n + 1 queries problem by prefetching a relation by name