UniqueConstraint declared in inheritance (child) entity can't reach related object id #6498

Closed
opened 2026-01-22 15:34:08 +01:00 by admin · 0 comments
Owner

Originally created by @remoteclient on GitHub (Jul 8, 2020).

Bug Report

I have a CustomerAddress with an embedded Address. This has a relation to a Customer.

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                                      http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="MWS\CustomerBundle\Entity\CustomerAddress"
            table="mws_customer_address"
            inheritance-type="JOINED"
            repository-class="MWS\CustomerBundle\Repository\AddressRepository"
    >
        <discriminator-column name="type" type="string" />
        <discriminator-map>
            <discriminator-mapping value="address" class="CustomerAddress"/>
            <discriminator-mapping value="billing" class="BillingAddress"/>
            <discriminator-mapping value="delivery" class="DeliveryAddress"/>
        </discriminator-map>

        <id name="id" type="integer" column="id">
            <generator strategy="IDENTITY"/>
        </id>

        <field name="uuid" column="uuid" type="guid" />

        <embedded name="address" class="Address" />

        <field name="addressType" type="mws_address_type" column="address_type" />
        <field name="showOnMap" type="boolean" column="show_on_map"/>

        <many-to-one field="customer"
                     inversed-by="customerAddresses"
                     target-entity="MWS\CustomerBundle\Entity\Customer">
            <join-column name="customer_id"
                         referenced-column-name="id"
                         nullable="false"
                         on-delete="CASCADE"
            />
        </many-to-one>

    </entity>
</doctrine-mapping>

BillingAddress and DeliveryAddress inherit from this CustomerAddress.

I want a BillingAddress and CustomerAddress to be unique for a Customer so that a Customer can have the same address set as BillingAddress and DeliveryAddress but never the same address twice as maybe DeliverAddress for one Customer.

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                                      http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
>

    <entity name="MWS\CustomerBundle\Entity\BillingAddress"
            table="mws_customer_billing_address"
    >

        <unique-constraints>
            <unique-constraint columns="customer_id,address_line_1,address_line_2,address_line_3,address_line_4,address_city,address_zip_postcode,address_country" name="billing_address"/>
        </unique-constraints>

    </entity>
</doctrine-mapping>
Q A
BC Break no
Version 2.7.3

Summary

When I try to update the database I get There is no column with name 'customer_id' on table 'mws_customer_billing_address'. Which obviously isn't right. So I can not have the desired behaviour.

Expected behavior

Expected behaviour is, that the unique constraint sees the related customer id

Maybe related: #6248

Originally created by @remoteclient on GitHub (Jul 8, 2020). ### Bug Report I have a `CustomerAddress` with an embedded `Address`. This has a relation to a `Customer`. ```xml <?xml version="1.0" encoding="utf-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity name="MWS\CustomerBundle\Entity\CustomerAddress" table="mws_customer_address" inheritance-type="JOINED" repository-class="MWS\CustomerBundle\Repository\AddressRepository" > <discriminator-column name="type" type="string" /> <discriminator-map> <discriminator-mapping value="address" class="CustomerAddress"/> <discriminator-mapping value="billing" class="BillingAddress"/> <discriminator-mapping value="delivery" class="DeliveryAddress"/> </discriminator-map> <id name="id" type="integer" column="id"> <generator strategy="IDENTITY"/> </id> <field name="uuid" column="uuid" type="guid" /> <embedded name="address" class="Address" /> <field name="addressType" type="mws_address_type" column="address_type" /> <field name="showOnMap" type="boolean" column="show_on_map"/> <many-to-one field="customer" inversed-by="customerAddresses" target-entity="MWS\CustomerBundle\Entity\Customer"> <join-column name="customer_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" /> </many-to-one> </entity> </doctrine-mapping> ``` `BillingAddress` and `DeliveryAddress` inherit from this `CustomerAddress`. I want a `BillingAddress` and `CustomerAddress` to be unique for a `Customer` so that a Customer can have the same address set as `BillingAddress` and `DeliveryAddress` but never the same address twice as maybe `DeliverAddress` for one `Customer`. ```xml <?xml version="1.0" encoding="utf-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd" > <entity name="MWS\CustomerBundle\Entity\BillingAddress" table="mws_customer_billing_address" > <unique-constraints> <unique-constraint columns="customer_id,address_line_1,address_line_2,address_line_3,address_line_4,address_city,address_zip_postcode,address_country" name="billing_address"/> </unique-constraints> </entity> </doctrine-mapping> ``` | Q | A |------------ | ------ | BC Break |no | Version |2.7.3 #### Summary When I try to update the database I get ` There is no column with name 'customer_id' on table 'mws_customer_billing_address'.` Which obviously isn't right. So I can not have the desired behaviour. #### Expected behavior Expected behaviour is, that the unique constraint sees the related customer id Maybe related: #6248
admin closed this issue 2026-01-22 15:34:08 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6498