12. Troubleshooting

12.1. Deleted elements from a one-to-many association are not removed!

Make sure the Orphan Removal option is set to true:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="Application\Sonata\MediaBundle\Entity\Gallery" table="media__gallery" >

        <one-to-many
            field="galleryHasMedias"
            target-entity="Application\Sonata\MediaBundle\Entity\GalleryHasMedia"
            mapped-by="gallery"
            orphan-removal="true"
            >

            <orphan-removal>true</orphan-removal>

        </one-to-many>

        <!-- other definitions -->
    </entity>
</doctrine-mapping>

Note

The last Doctrine version requires to define the orphan-removal as an attribute and not as a node.

12.2. Ordered fields are not ordered!

Make sure the order-by option is correctly set:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="Application\Sonata\MediaBundle\Entity\Gallery" table="media__gallery" >

        <one-to-many
            field="galleryHasMedias"
            target-entity="Application\Sonata\MediaBundle\Entity\GalleryHasMedia"
            mapped-by="gallery"
            >
            <order-by>
                <order-by-field name="position" direction="ASC"/>
            </order-by>

        </one-to-many>

        <!-- other definitions -->

    </entity>
</doctrine-mapping>