As i know, getting result from database using doctrine will return an array of object and its field name is the entity property name but not table column name.
My HomeBanner Entity:
class HomeBanner
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $imageName;
/**
* @ORM\Column(type="string", length=255)
*/
private $caption;
/**
* @ORM\Column(type="date")
*/
private $updatedAt;
}
In database table, the column name is like:
---------------
| id |
| image_name |
| caption |
| updated_at |
---------------
In HomeBannerRepository, i create a new method and return array result:
return $this->createQueryBuilder('h')->getQuery()->getArrayResult();
It give me:
[id] => 1,
[imageName] => test.jpg,
[caption] => helloworld,
[updatedAt] => 2019/06/18
But what i want is:
[id] => 1,
[image_name] => test.jpg,
[caption] => helloworld,
[updated_at] => 2019/06/18
Is there another way to get result with table column name (not object property name) without directly with SQL query?