Details
Description
As we read in the documentation, 'datetime' fields are casted by Doctrine to PHP DateTime class objects. However, when we want to get only certain fields from a table using DQL, Doctrine casts the datetime value to ordinary string. Consider the following example:
Column definition
/** * @var DateTime $active * * @Column(name="registered", type="datetime") */ private $registered;
Query
var_dump($em->createQuery('SELECT u.id, u.registered FROM Entities\\User u')->getResult());
Expected result:
- The returned row contains DateTime object for 'registered' column.
Actual result:
- The returned row contains string for 'registered' column.
If this is an intended feature, first of all, it should be clearly pointed in the documentation that Doctrine types do not apply in such situations, and secondly, I think it is a very bad practice. I use Doctrine and tell him I have a datetime field in order to get Datetime objects automatically, not to deal with manual conversions.
oh wait, i am just now looking at your query, you are retrieving the values as scalar fields, that is something totally different. Let me check the code on this issue.