<?xml version="1.0" encoding="UTF-8"?>

<!--

 This file is part of the Sylius package.

 (c) Sylius Sp. z o.o.

 For the full copyright and license information, please view the LICENSE
 file that was distributed with this source code.

-->

<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">
    <mapped-superclass name="Sylius\Component\Core\Model\Customer" table="sylius_customer">
        <indexes>
            <index name="created_at_index" columns="created_at" />
        </indexes>

        <one-to-one field="defaultAddress" target-entity="Sylius\Component\Addressing\Model\AddressInterface">
            <join-column name="default_address_id" on-delete="SET NULL" />
            <cascade>
                <cascade-persist />
            </cascade>
        </one-to-one>

        <one-to-one field="user" target-entity="Sylius\Component\Core\Model\ShopUserInterface" mapped-by="customer">
            <cascade>
                <cascade-all/>
            </cascade>
        </one-to-one>

        <one-to-many field="orders" target-entity="Sylius\Component\Order\Model\OrderInterface" mapped-by="customer">
            <order-by>
                <order-by-field name="id" />
            </order-by>

            <cascade>
                <cascade-all />
            </cascade>
        </one-to-many>
        <one-to-many field="addresses" target-entity="Sylius\Component\Addressing\Model\AddressInterface" mapped-by="customer">
            <order-by>
                <order-by-field name="id" />
            </order-by>

            <cascade>
                <cascade-all />
            </cascade>
        </one-to-many>
    </mapped-superclass>
</doctrine-mapping>
