Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Joined table inheritance with AttributeOverride (rename) of the identifier column fails on insert #8229

@cziegenberg

Description

@cziegenberg

In the following example, the automatically created insert into the resource table fails when creating a new user, because the id field got another column name in the user table, using the AttributeOverride annotation:

// src/Entity/Resource.php

/**
 * @ORM\Entity()
 * @ORM\Table(name="app_resource")
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="resource_type", type="string", length=191)
 * @ORM\DiscriminatorMap({"resource"="Resource", "user"="User"})
 */
abstract class Resource
{
    /**
     * @ORM\Id()
     * @ORM\Column(name="resource_id", type="guid")
     */
    protected string $id;
}

// src/Entity/User.php

/**
 * @ORM\Entity()
 * @ORM\Table(name="app_user")
 * @ORM\AttributeOverrides({@ORM\AttributeOverride(name="id", column=@ORM\Column(name="user_id", type="guid"))})
 */
class User extends Resource
{
    //...
}

Error (meaning only one parameter instead of two given for the prepared statement, because the id value is not set):

  [Doctrine\DBAL\Driver\PDOException (08P01)]                                                                                      
  SQLSTATE[08P01]: <<Unknown error>>: 7 FEHLER:  Binden-Nachricht enthält 1 Parameter, aber vorbereitete Anweisung »« erfordert 2 

Also reading the entity, updating it and deleting it fails. I have a working fix for it, tested with the 2.8.x and the 2.7.x branch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions