Wizard Wizard - 1 month ago 12
PHP Question

Doctrine returning join query in different arrays

$query = $this->createQueryBuilder('p');
$query
->select('s', 'p')
->innerJoin(
'test\Entity\ProductQuantity',
's',
\Doctrine\ORM\Query\Expr\Join::WITH,
'p.sku = s.sku'
)
->orderBy('p.productId', 'DESC');

return $query->getQuery()->getResult();


This query must return result of 2 tables, what I get:

result = array(
[0] => 'table1',
[1]=> 'table2',
[2] => 'table1',
[3]=> 'table2',
)


Why I'm get 2 tables in 2 arrays ? this is join query and it must be in 1 array, how to merge result of join query in 1 array and get:

result = array(
[0] => 'table1table2',
[1] => 'table1table2',
)

Answer

Solution in add to select needed fields and then result is 1 array

    $query = $this->createQueryBuilder('p');
    $query
        ->select('p.sku', 's.quantity', 'p.priceAmount')
        ->innerJoin(
            'LeosEbayGateway\Entity\ProductQuantity',
            's',
            \Doctrine\ORM\Query\Expr\Join::WITH,
            'p.sku = s.sku'
        )
        ->orderBy('p.productId', 'DESC');

    return $query->getQuery()->getResult();

Result:

result = array(
[0] => 'table1table2',
[1] => 'table1table2',
)