Possible bug in ManyToMany Bidirectional relation when the join column name called not "ID"? #6674

Closed
opened 2026-01-22 15:36:50 +01:00 by admin · 1 comment
Owner

Originally created by @BonBonSlick on GitHub (Apr 1, 2021).

<many-to-many target-entity="App\Domain\AccessControlListPack\Role\Entity\Role"
                      field="roles"
                      inversed-by="features"
                      index-by="uuid"
        >
            <cascade>
                <cascade-persist/>
            </cascade>
            <join-table name="roles_features">
                <join-columns>
                    <join-column name="feature_uuid" referenced-column-name="uuid" nullable="false" unique="false"/>
                </join-columns>
                <inverse-join-columns>
                    <join-column name="role_uuid" referenced-column-name="uuid" nullable="false"/>
                </inverse-join-columns>
            </join-table>
        </many-to-many>


  <many-to-many target-entity="App\Domain\AccessControlListPack\FeatureTag\Entity\RoleFeatureTag"
                      field="features"
                      inversed-by="roles"
                      index-by="uuid"
        >
            <cascade>
                <cascade-persist/>
            </cascade>
            <join-table name="roles_features">
                <join-columns>
                    <join-column name="role_uuid" referenced-column-name="uuid" nullable="false"/>
                </join-columns>
                <inverse-join-columns>
                    <join-column name="feature_uuid" referenced-column-name="uuid" nullable="false"/>
                </inverse-join-columns>
            </join-table>
        </many-to-many>

Adding join-table to both mappings throws

In SchemaException.php line 112:
                                                                 
  The table with name 'postgres.roles_features' already exists.

removing join table on any mapping, owning side or inverse will cause

In MappingException.php line 165:
                                                                                                                 
  No mapping found for field 'id' on class 'App\Domain\AccessControlListPack\FeatureTag\Entity\RoleFeatureTag'.

Probable defaults and join table issue .

Tell me please, is there any way, workaround to specify custom join column names in Bidirectional ManyToMany for both owning and inverse side mappings?

Originally created by @BonBonSlick on GitHub (Apr 1, 2021). ``` <many-to-many target-entity="App\Domain\AccessControlListPack\Role\Entity\Role" field="roles" inversed-by="features" index-by="uuid" > <cascade> <cascade-persist/> </cascade> <join-table name="roles_features"> <join-columns> <join-column name="feature_uuid" referenced-column-name="uuid" nullable="false" unique="false"/> </join-columns> <inverse-join-columns> <join-column name="role_uuid" referenced-column-name="uuid" nullable="false"/> </inverse-join-columns> </join-table> </many-to-many> <many-to-many target-entity="App\Domain\AccessControlListPack\FeatureTag\Entity\RoleFeatureTag" field="features" inversed-by="roles" index-by="uuid" > <cascade> <cascade-persist/> </cascade> <join-table name="roles_features"> <join-columns> <join-column name="role_uuid" referenced-column-name="uuid" nullable="false"/> </join-columns> <inverse-join-columns> <join-column name="feature_uuid" referenced-column-name="uuid" nullable="false"/> </inverse-join-columns> </join-table> </many-to-many> ``` Adding join-table to both mappings throws ``` In SchemaException.php line 112: The table with name 'postgres.roles_features' already exists. ``` removing join table on any mapping, owning side or inverse will cause ``` In MappingException.php line 165: No mapping found for field 'id' on class 'App\Domain\AccessControlListPack\FeatureTag\Entity\RoleFeatureTag'. ``` Probable [defaults and join table issue ](https://www.doctrine-project.org/projects/doctrine-orm/en/2.8/reference/association-mapping.html#mapping-defaults). Tell me please, is there any way, workaround to specify custom join column names in Bidirectional ManyToMany for both owning and inverse side mappings?
admin closed this issue 2026-01-22 15:36:50 +01:00
Author
Owner

@BonBonSlick commented on GitHub (Apr 2, 2021):

Sorry, was late night, mapped-by on inversed side must be...

@BonBonSlick commented on GitHub (Apr 2, 2021): Sorry, was late night, mapped-by on inversed side must be...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6674