0

i have this situation

<entity name="Company\Entity\User\User" table="usr_user" inheritance-type="JOINED">
    <unique-constraints>
        <unique-constraint name="username_UNIQUE" columns="username" />
    </unique-constraints>
    <discriminator-column name="discriminator" />
    <discriminator-map>
        <discriminator-mapping value="guest" class="\Company\Entity\User\Guest"></discriminator-mapping>
        <discriminator-mapping value="user" class="\Company\Entity\User\User"></discriminator-mapping>
    </discriminator-map>
    <id name="id" type="integer" column="id">
        <generator strategy="AUTO" />
    </id>
    <field name="username" type="string" column="username" length="255" />
    <field name="password" type="string" column="password" length="50" />
</entity>

<entity name="Company\Entity\User\Guest" table="usr_guest">
    <id name="id" type="integer" column="id">
        <generator strategy="AUTO" />
    </id>
    <field name="additionalField1" type="string" column="additional_field_1" length="255" />
    <field name="additionalField1" type="string" column="additional_field_2" length="255" />
</entity>

When i generate entities i add the inheritance

class User {
 // Some code...
}

class Guest extends User{
 // Some code...
}

The problem appears whe i try to update database schema because of the same "id" column name of both the entities. I've tryied to add an attribute override but i guess this is not the proper way

<entity name="Company\Entity\User\Guest" table="usr_guest">

    <id name="id" type="integer" column="id">
        <generator strategy="AUTO" />
    </id>
    <field name="additionalField1" type="string" column="additional_field_1" length="255" />
    <field name="additionalField1" type="string" column="additional_field_2" length="255" />
    <attribute-override name="id">
                <field column="guest_id" />
            </attribute-override>
</entity>

I've tryied also to change the property name (not the column name) in guest_id but the error is the same

 [Doctrine\ORM\Mapping\MappingException]
  Duplicate definition of column 'id' on entity 'Company\Entity\User\Guest' in a field or discriminator column mapping.

Do i have to change the Guest "id" column name? Where am i wrong?

Thank You

4

1 回答 1

0

为了使这个问题的状态得到回答,并从此

<entity name="Company\Entity\User\Guest" table="usr_guest">
    <field name="additionalField1" type="string" column="additional_field_1" length="255" />
    <field name="additionalField1" type="string" column="additional_field_2" length="255" />
    <attribute-override name="id">
      <field column="guest_id" />
    </attribute-override>
</entity>

<entity name="Company\Entity\User\User" table="usr_user" inheritance-type="JOINED">
    <id name="id" type="integer" column="id">
        <generator strategy="AUTO" />
    </id>
    <unique-constraints>
        <unique-constraint name="username_UNIQUE" columns="username" />
    </unique-constraints>
    <discriminator-column name="discriminator" />
    <discriminator-map>
        <discriminator-mapping value="guest" class="\Company\Entity\User\Guest"></discriminator-mapping>
        <discriminator-mapping value="user" class="\Company\Entity\User\User"></discriminator-mapping>
    </discriminator-map>
    <field name="username" type="string" column="username" length="255" />
    <field name="password" type="string" column="password" length="50" />
</entity>

您必须删除继承表上的主键,因为它已经在母表上声明。

于 2016-12-06T10:48:08.453 回答