Many to Many bi-directional validation failing #6593

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

Originally created by @nspyke on GitHub (Dec 19, 2020).

Doctrine ORM version 2.7.4
Symfony 4.4.17

I'm getting this validation error, even though as far as I can tell, my XML is correct

[FAIL] The entity-class Core\Entity\Notification\NotificationSetting mapping is invalid:

  • The field Core\Entity\Notification\NotificationSetting#assets is on the inverse side of a bi-directional relationship, but the specified mappedBy association on the target-entity Core\Entity\Asset\Vehicle#notificationSettings does not contain the required 'inversedBy="assets"' attribute.

If I change both sides to use inversed-by then the validation error goes away, which seems weird because i'm pretty sure that that's an invalid configuration.

Owning side

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"           
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity repository-class="Core\Repository\Asset\VehicleRepository"
            name="Core\Entity\Asset\Vehicle"
            table="vehicles">
        ...
        <many-to-many field="notificationSettings" inversed-by="assets" target-entity="Core\Entity\Notification\NotificationSetting">
            <cascade>
                <cascade-persist/>
            </cascade>
        </many-to-many>
    </entity>
</doctrine-mapping>

Inverse side

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
    xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="Core\Entity\Notification\NotificationSetting"
            repository-class="Core\Repository\Notification\NotificationSettingRepository"
            table="notification_settings">

        <many-to-many field="assets" target-entity="Core\Entity\Asset\Vehicle" mapped-by="notificationSettings">
            <cascade>
                <cascade-persist/>
            </cascade>
        </many-to-many>
    </entity>
</doctrine-mapping>

Same validation error if I also changed mapped-by to inversed-by on NotificationSetting and mapped-by to inversed-by on Vehicle.

Originally created by @nspyke on GitHub (Dec 19, 2020). Doctrine ORM version 2.7.4 Symfony 4.4.17 I'm getting this validation error, even though as far as I can tell, my XML is correct [FAIL] The entity-class Core\Entity\Notification\NotificationSetting mapping is invalid: * The field Core\Entity\Notification\NotificationSetting#assets is on the inverse side of a bi-directional relationship, but the specified mappedBy association on the target-entity Core\Entity\Asset\Vehicle#notificationSettings does not contain the required 'inversedBy="assets"' attribute. If I change both sides to use inversed-by then the validation error goes away, which seems weird because i'm pretty sure that that's an invalid configuration. Owning side ```xml <?xml version="1.0" encoding="utf-8"?> <doctrine-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity repository-class="Core\Repository\Asset\VehicleRepository" name="Core\Entity\Asset\Vehicle" table="vehicles"> ... <many-to-many field="notificationSettings" inversed-by="assets" target-entity="Core\Entity\Notification\NotificationSetting"> <cascade> <cascade-persist/> </cascade> </many-to-many> </entity> </doctrine-mapping> ``` Inverse side ```xml <?xml version="1.0" encoding="utf-8"?> <doctrine-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity name="Core\Entity\Notification\NotificationSetting" repository-class="Core\Repository\Notification\NotificationSettingRepository" table="notification_settings"> <many-to-many field="assets" target-entity="Core\Entity\Asset\Vehicle" mapped-by="notificationSettings"> <cascade> <cascade-persist/> </cascade> </many-to-many> </entity> </doctrine-mapping> ``` Same validation error if I also changed mapped-by to inversed-by on NotificationSetting and mapped-by to inversed-by on Vehicle.
admin closed this issue 2026-01-22 15:35:29 +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#6593