I am currently refactoring an application written in Symfony 3 and relies heavily on Doctrine ORM and I'm stuck trying to get an object/array with indexes of my selected columns.
Now I am fairly familiar with PHP PDO and as I recall a basic fetch of query results as shown below
$sth->fetchAll();
(Depending on my query) it would give me an array similar to the one below
[0] => Array
(
[name] => pear
[0] => pear
[colour] => green
[1] => green
)
[1] => Array
(
[name] => watermelon
[0] => watermelon
[colour] => pink
[1] => pink
)
With Doctrine i have tried to use several inbuilt functions with Hydration parameters
$query->getResult();
And with no luck I end up getting something like this
Array
(
[0] => Array
(
[name] => pear
[colour] => green
)
[1] => Array
(
[name] => Watermelon
[colour] => Pink
)
)
Can someone help me or point me in the right direction how to properly have this sorted out?
------Updated the question to include the full method I am currently using----
public function getDepartmentCount()
{
$qb = $this->createQueryBuilder('fruit')
->leftJoin('fruit.color','color')
$query=$qb->getQuery();
return $query->getArrayResult(); //Method that possibly needs to be changed
}