Skip to content

Loading…

DDC-1316: Insert statement for joined subclass presister doesn't type change the id values for subtables #1930

Closed
doctrinebot opened this Issue · 7 comments

2 participants

@doctrinebot

Jira issue originally created by user vigor_bg:

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<ins></ins>, $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<ins></ins>, $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

@doctrinebot

Comment created by @beberlei:

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

@doctrinebot

Comment created by @beberlei:

Changed to improvement and link to DDC-1320

@doctrinebot

Comment created by @guilhermeblanco:

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: 666691f

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot

Comment created by @beberlei:

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

@doctrinebot

Comment created by @beberlei:

Merged into 2.1.x

@doctrinebot doctrinebot added this to the 2.1.3 milestone
@doctrinebot doctrinebot closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.