<?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\ShippingMethod" table="sylius_shipping_method">
        <many-to-one field="zone" target-entity="Sylius\Component\Addressing\Model\ZoneInterface">
            <join-column name="zone_id" referenced-column-name="id" nullable="false" />
        </many-to-one>

        <many-to-one field="taxCategory" target-entity="Sylius\Component\Taxation\Model\TaxCategoryInterface">
            <join-column name="tax_category_id" referenced-column-name="id" nullable="true" on-delete="SET NULL" />
        </many-to-one>

        <many-to-many field="channels" target-entity="Sylius\Component\Channel\Model\ChannelInterface">
            <order-by>
                <order-by-field name="id" />
            </order-by>

            <join-table name="sylius_shipping_method_channels">
                <join-columns>
                    <join-column name="shipping_method_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" />
                </join-columns>
                <inverse-join-columns>
                    <join-column name="channel_id" referenced-column-name="id" nullable="false" on-delete="CASCADE" />
                </inverse-join-columns>
            </join-table>
        </many-to-many>
    </mapped-superclass>

</doctrine-mapping>
