B
B
BonBon Slick2021-04-02 01:28:30
Doctrine ORM
BonBon Slick, 2021-04-02 01:28:30

Bug in Many-To-Many, Bidirectional?

<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>


The ID field is UUID.
The owning side comes out of the Role example, so join_table is declared in the role mapping.
1 - if declared in both mappings there will be an error
In SchemaException.php line 112:
                                                                 
  The table with name 'postgres.roles_features' already exists.

2 - remove in any of the mappings, then it will give an error
In MappingException.php line 165:
                                                                                                                 
  No mapping found for field 'id' on class 'App\Domain\AccessControlListPack\FeatureTag\Entity\RoleFeatureTag'.

Because doctrine by default maps to the ID field

Is there any workaround?
Changing the UUID of the field name to id means changing the field name on all entities, which will entail tons of side effects.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BoShurik, 2021-04-02
@BonBonSlick

https://www.doctrine-project.org/projects/doctrine...
You have it everywhere inversed-by, although on the second side it should be mapped-bywithout join-table
The part about id is not clear. What is the problem with changing the value of referenced-column-name="id", where will the side effects come from?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question