I have an entity as follow:
private $username;
private $password;
private $createdAt; //datetime
I want to run the query in doctrine to get the entities with the existing fields plus another field (in this case a column showing difference of createdAt and current datetime in minutes.
In sql I would run query like:
select username, password, createdAt,TIMESTAMPDIFF(MINUTE , created_at, NOW()) AS minutes from users
In doctrine I fetched the entity as below:
$user = $em->getRepository('TestBundle:Users');
How can I get the custom field minutes from doctrine?
You should check ResultSetMapping:
And check how to add scalar result