source/Spiral/ORM/Entities/Relations/ManyToManyRelation.php
protected function createQuery($innerKey): SelectQuery
    {
        $table = $this->orm->table($this->class);
        $query = $table->select();

        //Loader will take care of query configuration
        $loader = new ManyToManyLoader(
            $this->class,
            $table->getName(),
            $this->schema,
            $this->orm,
            $this->targetRole()
        );

        //This is root loader, we can do self-alias (THIS IS SAFE due loader in POSTLOAD mode)
        $loader = $loader->withContext(
            $loader,
            [
                'alias'      => $table->getName(),
                'pivotAlias' => $table->getName() . '_pivot',
                'method'     => RelationLoader::POSTLOAD
            ]
        );

        //Configuring query using parent inner key value as reference
        /** @var ManyToManyLoader $loader */
        $query = $loader->configureQuery($query, true, [$innerKey]);

        //Additional pivot conditions
        $pivotDecorator = new AliasDecorator($query, 'onWhere', $table->getName() . '_pivot');
        $pivotDecorator->where($this->schema[Record::WHERE_PIVOT]);

        $decorator = new AliasDecorator($query, 'where', 'root');

        //Additional where conditions!
        if (!empty($this->schema[Record::WHERE])) {
            $decorator->where($this->schema[Record::WHERE]);
        }

        if (!empty($this->schema[Record::ORDER_BY])) {
            //Sorting
            $decorator->orderBy((array)$this->schema[Record::ORDER_BY]);
        }

        return $query;
    }
protected function createQuery($innerKey): SelectQuery
    {
        $table = $this->orm->table($this->class);
        $query = $table->select();

        //Loader will take care of query configuration
        $loader = new ManyToManyLoader(
            $this->class,
            $table->getName(),
            $this->schema,
            $this->orm,
            $this->targetRole()
        );

        //This is root loader, we can do self-alias (THIS IS SAFE due loader in POSTLOAD mode)
        $loader = $loader->withContext(
            $loader,
            [
                'alias'      => $table->getName(),
                'pivotAlias' => $table->getName() . '_pivot',
                'method'     => RelationLoader::POSTLOAD
            ]
        );

        //Configuring query using parent inner key value as reference
        /** @var ManyToManyLoader $loader */
        $query = $loader->configureQuery($query, true, [$innerKey]);

        //Additional pivot conditions
        $pivotDecorator = new AliasDecorator($query, 'onWhere', $table->getName() . '_pivot');
        $pivotDecorator->where($this->schema[Record::WHERE_PIVOT]);

        $decorator = new AliasDecorator($query, 'where', 'root');

        //Additional where conditions!
        if (!empty($this->schema[Record::WHERE])) {
            $decorator->where($this->schema[Record::WHERE]);
        }

        if (!empty($this->schema[Record::ORDER_BY])) {
            //Sorting
            $decorator->orderBy((array)$this->schema[Record::ORDER_BY]);
        }

        return $query;
    }
protected function createQuery ( $ innerKey ) : SelectQuery { $ table = $ this -> orm -> table ( $ this -> class ) ; $ query = $ table -> select ( ) ; //Loader will take care of query configuration $ loader = new ManyToManyLoader ( $ this -> class , $ table -> getName ( ) , $ this -> schema , $ this -> orm , $ this -> targetRole ( ) ) ; //This is root loader, we can do self-alias (THIS IS SAFE due loader in POSTLOAD mode) $ loader = $ loader -> withContext ( $ loader , [ 'alias' => $ table -> getName ( ) , 'pivotAlias' => $ table -> getName ( ) . '_pivot' , 'method' => RelationLoader :: POSTLOAD ] ) ; //Configuring query using parent inner key value as reference /** @var ManyToManyLoader $loader */ $ query = $ loader -> configureQuery ( $ query , true , [ $ innerKey ] ) ; //Additional pivot conditions $ pivotDecorator = new AliasDecorator ( $ query , 'onWhere' , $ table -> getName ( ) . '_pivot' ) ; $ pivotDecorator -> where ( $ this -> schema [ Record :: WHERE_PIVOT ] ) ; $ decorator = new AliasDecorator ( $ query , 'where' , 'root' ) ; //Additional where conditions! if ( ! empty ( $ this -> schema [ Record :: WHERE ] ) ) { $ decorator -> where ( $ this -> schema [ Record :: WHERE ] ) ; } if ( ! empty ( $ this -> schema [ Record :: ORDER_BY ] ) ) { //Sorting $ decorator -> orderBy ( ( array ) $ this -> schema [ Record :: ORDER_BY ] ) ; } return $ query ; }
Create query for lazy loading.

@param mixed $innerKey

@return SelectQuery
Create query for lazy loading .