Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1316

Insert statement for joined subclass presister doesn't type change the id values for subtables

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.1
    • Fix Version/s: 2.1.3
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      Hi there,

      I am using "Class Table Inheritance" and this are my entities.

      **
       * @Entity
       * @Table (name="Vehicles")
       * @InheritanceType ("JOINED")
       * @DiscriminatorColumn (name="vehicleClass", type="string")
       * @DiscriminatorMap ({"own"="OwnCar", "renta"="RentedCar"})
       */
      class Vehicle
      {
      
      	/**
      	 * @Id
      	 * @Column (name="vehicleID", type="integer")
      	 */
      	protected $vehicleID;
      
              /**
      	 * @Id
               * @Column (name="dateFrom", type="datetime")
               */
      	protected $dateFrom;
      
             .........
      }
      
      /**
       * @Table (name="OwnCars")
       * @Entity (repositoryClass="OwnCarRepo")
       */
      class OwnCars_Model_Entity_OwnCar extends OwnCars_Model_Entity_Vehicle {
      
      }
      

      As you can see i am using composed id keys. The problem that i get is when building the insert statement the value for the second key which is type datetime is not transformed to date transformed but cast to integer and in the data base i got inserted value of 0000-00-00 00:00:00 instead of the date that i have given. After i did a bit of debugging i found the problem to be in the "Doctrine\ORM\Persisters\JoinedSubclassPersister" on line 163.

      foreach ((array) $id as $idVal) {
          $stmt->bindValue($paramIndex++, $idVal);
      }
      

      As you can see when you are binding the values for the subtable ids you are not giving the type for the id. So for me to work i did a quick fix:

      foreach ((array) $id as $columnNameIdentifier => $idVal) {
      
          /**
           * Fix untyped join inherited table.
           * All identifiers was typed now.
           */
          $type = \PDO::PARAM_STR;
          if (isset($this->_columnTypes[$columnNameIdentifier])) {
              $type = $this->_columnTypes[$columnNameIdentifier];
          }
      
          $stmt->bindValue($paramIndex++, $idVal, $type);
      }
      

      I hope that you will have time to take a look in to that problem soon as it is important for my project. Otherwise great work so far with the "ORM"

      Have a nice day,
      Victor

        Issue Links

          Activity

          Hide
          Benjamin Eberlei added a comment -

          Even if we fixed that it wouldn't work to have a DateTime as primary key. Since PK values need to be "stringable".

          Show
          Benjamin Eberlei added a comment - Even if we fixed that it wouldn't work to have a DateTime as primary key. Since PK values need to be "stringable".
          Hide
          Benjamin Eberlei added a comment -

          Changed to improvement and link to DDC-1320

          Show
          Benjamin Eberlei added a comment - Changed to improvement and link to DDC-1320
          Hide
          Guilherme Blanco added a comment -

          Even though DateTime would be solved in a different way, I think the patch must be applied specially because the identifier can be anything else, including a user customized type.

          I fixed this issue by commit: https://github.com/doctrine/doctrine2/commit/666691f84fd5a48d0eb6af7e93b83c2651555e61

          Show
          Guilherme Blanco added a comment - Even though DateTime would be solved in a different way, I think the patch must be applied specially because the identifier can be anything else, including a user customized type. I fixed this issue by commit: https://github.com/doctrine/doctrine2/commit/666691f84fd5a48d0eb6af7e93b83c2651555e61
          Hide
          Benjamin Eberlei added a comment -

          Set to 2.2-DEV as one thing is unclear for me, see commit comment.

          Show
          Benjamin Eberlei added a comment - Set to 2.2-DEV as one thing is unclear for me, see commit comment.
          Hide
          Benjamin Eberlei added a comment -

          Merged into 2.1.x

          Show
          Benjamin Eberlei added a comment - Merged into 2.1.x

            People

            • Assignee:
              Guilherme Blanco
              Reporter:
              victor Velkov
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: