public static function addJoin($query, $parentAlias, $schema, $relName, $nested=array(), $joinType='inner')
    {
        if (!in_array($joinType, array('inner','left','right'))) {
            throw new \InvalidArgumentException("Unsupported join type: $joinType");
        }

        list($relName, $alias) = self::parseRelName($relName);
        $rel = $schema->relationship($relName);

        // look up schema and table for both sides of join
        $instance = \Pheasant::instance();
        $localTable = $instance->mapperFor($schema->className())->table();
        $remoteSchema = $instance->schema($rel->class);
        $remoteTable = $instance->mapperFor($rel->class)->table();

        $joinMethod = $joinType.'Join';
        $query->$joinMethod($remoteTable->name()->table, sprintf(
            'ON `%s`.`%s`=`%s`.`%s`',
            $parentAlias,
            $rel->local,
            $alias,
            $rel->foreign
            ),
            $alias
        );

        foreach (self::normalizeMap($nested) as $relName=>$nested) {
            self::addJoin($query, $alias, $remoteSchema, $relName, $nested, $joinType);
        }
    }
public static function addJoin($query, $parentAlias, $schema, $relName, $nested=array(), $joinType='inner')
    {
        if (!in_array($joinType, array('inner','left','right'))) {
            throw new \InvalidArgumentException("Unsupported join type: $joinType");
        }

        list($relName, $alias) = self::parseRelName($relName);
        $rel = $schema->relationship($relName);

        // look up schema and table for both sides of join
        $instance = \Pheasant::instance();
        $localTable = $instance->mapperFor($schema->className())->table();
        $remoteSchema = $instance->schema($rel->class);
        $remoteTable = $instance->mapperFor($rel->class)->table();

        $joinMethod = $joinType.'Join';
        $query->$joinMethod($remoteTable->name()->table, sprintf(
            'ON `%s`.`%s`=`%s`.`%s`',
            $parentAlias,
            $rel->local,
            $alias,
            $rel->foreign
            ),
            $alias
        );

        foreach (self::normalizeMap($nested) as $relName=>$nested) {
            self::addJoin($query, $alias, $remoteSchema, $relName, $nested, $joinType);
        }
    }
public static function addJoin ( $ query , $ parentAlias , $ schema , $ relName , $ nested = array ( ) , $ joinType = 'inner' ) { if ( ! in_array ( $ joinType , array ( 'inner' , 'left' , 'right' ) ) ) { throw new \ InvalidArgumentException ( "Unsupported join type: $joinType" ) ; } list ( $ relName , $ alias ) = self :: parseRelName ( $ relName ) ; $ rel = $ schema -> relationship ( $ relName ) ; // look up schema and table for both sides of join $ instance = \ Pheasant :: instance ( ) ; $ localTable = $ instance -> mapperFor ( $ schema -> className ( ) ) -> table ( ) ; $ remoteSchema = $ instance -> schema ( $ rel -> class ) ; $ remoteTable = $ instance -> mapperFor ( $ rel -> class ) -> table ( ) ; $ joinMethod = $ joinType . 'Join' ; $ query -> $ joinMethod ( $ remoteTable -> name ( ) -> table , sprintf ( 'ON `%s`.`%s`=`%s`.`%s`' , $ parentAlias , $ rel -> local , $ alias , $ rel -> foreign ) , $ alias ) ; foreach ( self :: normalizeMap ( $ nested ) as $ relName => $ nested ) { self :: addJoin ( $ query , $ alias , $ remoteSchema , $ relName , $ nested , $ joinType ) ; } }
Adds a join clause to the given query for the given schema and relationship. Optionally
takes a nested list of relationships that will be recursively joined as needed.
@return void
Adds a join clause to the given query for the given schema and relationship . Optionally takes a nested list of relationships that will be recursively joined as needed .