Ouzo\Db\Dialect\DialectUtil::buildJoinQueryPart PHP Method

buildJoinQueryPart() public static method

public static buildJoinQueryPart ( JoinClause $joinClause )
$joinClause Ouzo\Db\JoinClause
    public static function buildJoinQueryPart(JoinClause $joinClause)
    {
        $alias = $joinClause->alias ? " AS {$joinClause->alias}" : "";
        $on = self::buildWhereQuery($joinClause->onClauses);
        if ($joinClause->alias) {
            $on = preg_replace("#(?<=^| ){$joinClause->joinTable}(?=\\.)#", $joinClause->alias, $on);
        }
        return $joinClause->type . ' JOIN ' . $joinClause->joinTable . $alias . ' ON ' . $joinClause->getJoinColumnWithTable() . ' = ' . $joinClause->getJoinedColumnWithTable() . ($on ? " AND {$on}" : '');
    }

Usage Example

Esempio n. 1
0
 /**
  * @test
  */
 public function shouldNotReplaceWhenTableNameIsPartOfOtherTableName()
 {
     //given
     $onClauses = array(WhereClause::create('products.active = true'), WhereClause::create('order_products.active = true'));
     $joinClause = new JoinClause('products', 'id', 'product_id', 'order_products', 'p', 'LEFT', $onClauses);
     //when
     $buildJoinQueryPart = DialectUtil::buildJoinQueryPart($joinClause);
     //then
     Assert::thatString($buildJoinQueryPart)->isEqualTo('LEFT JOIN products AS p ON p.id = order_products.product_id AND p.active = true AND order_products.active = true');
 }