Ouzo\Db\Query::join PHP Method

join() public method

public join ( $joinTable, $joinKey, $idName, $alias = null, $type = 'LEFT', $on = [] )
    public function join($joinTable, $joinKey, $idName, $alias = null, $type = 'LEFT', $on = array())
    {
        $onClauses = array(WhereClause::create($on));
        $this->joinClauses[] = new JoinClause($joinTable, $joinKey, $idName, $this->aliasTable ?: $this->table, $alias, $type, $onClauses);
        return $this;
    }

Usage Example

コード例 #1
0
ファイル: MySqlDialectTest.php プロジェクト: letsdrink/ouzo
 /**
  * @test
  */
 public function shouldReturnSelectWithMultipleJoinsWithAliases()
 {
     //given
     $query = new Query();
     $query->table = 'products';
     $query->join('categories', 'id_category', 'id_category', 'c')->join('orders', 'id', 'id_product', 'o')->where('id = ?', 1);
     //when
     $sql = $this->_dialect->buildQuery($query);
     //then
     $expected = 'SELECT * FROM products LEFT JOIN categories AS c ON c.id_category = products.id_category LEFT JOIN orders AS o ON o.id = products.id_product WHERE id = ?';
     $this->assertEquals($expected, $sql);
 }