Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-657

DateTime objects casted to string in query results

    Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.3
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Linux, PostgreSQL 8.4

      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.

        Activity

          People

          • Assignee:
            Fabio B. Silva
            Reporter:
            Tomasz Jędrzejewski
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: