<?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:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-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\ProductTaxon" table="sylius_product_taxon">
        <unique-constraints>
            <unique-constraint columns="product_id,taxon_id" name="product_taxon_idx" />
        </unique-constraints>

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

        <field name="position" type="integer">
            <gedmo:sortable-position />
        </field>

        <many-to-one field="product" target-entity="Sylius\Component\Product\Model\ProductInterface" inversed-by="productTaxons">
            <join-column name="product_id" referenced-column-name="id" nullable="false" on-delete="CASCADE"/>
        </many-to-one>

        <many-to-one field="taxon" target-entity="Sylius\Component\Taxonomy\Model\TaxonInterface">
            <join-column name="taxon_id" referenced-column-name="id" nullable="false" on-delete="CASCADE"/>
            <gedmo:sortable-group />
        </many-to-one>
    </mapped-superclass>

</doctrine-mapping>
