How to add cascade argument in XML file format doctrine ORM

as far as I understand I need to add a "cascade" parameter to the mapping. But my mapping is in XML.
I found quite a bit of information about it but there was no result.
Pleace help!

Мy error is:
Multiple non-persisted new entities were found through the given association graph:nn * A new entity was found through the relationship ‘DomainMaintenanceMaintenance#affectedRegions’ that was not configured to cascade persist operations for entity: [email protected]7f1. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). If you cannot find out which entity causes the problem implement ‘DomainAffectedRegionAffectedRegion#__toString()’ to get a clue.n * A new entity was found through the relationship ‘DomainMaintenanceMaintenance#affectedRegions’ that was not configured to cascade persist operations for entity: [email protected]7f1. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={"persist"}). If you cannot find out which entity causes the problem implement ‘DomainAffectedRegionAffectedRegion#__toString()’ to get a clue.",

XML fails:

<entity name="DomainMaintenanceMaintenance" table="maintenances" repository-class="InfrastructureRepositoriesMaintenanceRepository">
    <id name="id" type="integer" column="id">
        <generator strategy="AUTO"/>
    </id>
    <field name="name" type="string"/>


    <one-to-many field="affectedRegions" target-entity="DomainAffectedRegionAffectedRegion" mapped-by="DomainMaintenanceMaintenance" />
   <cascade>
            <cascade-merge/>
        </cascade>


</entity>

<entity name="DomainAffectedRegionAffectedRegion" table="affected_regions" repository-class="InfrastructureRepositoriesAffectedRegionRepository">
    <id name="id" type="integer" column="id">
        <generator strategy="AUTO"/>
    </id>
   
    <many-to-one field="region" target-entity="DomainRegionRegion" inversed-by="DomainAffectedRegionAffectedRegion">
        <join-column name="region_id" referenced-column-name="id" />
        <cascade>
            <cascade-persist/>
        </cascade>
    </many-to-one>
    
     <many-to-one field="maintenance" target-entity="DomainMaintenanceMaintenance" inversed-by="DomainAffectedRegionAffectedRegion">
        <join-column name="maintenance_id" referenced-column-name="id" />
       <cascade>
            <cascade-persist/>
        </cascade>
    </many-to-one>
    

    <field name="vlans" type="string"/>
    <field name="olts" type="string"/>
   

</entity>

<entity name="DomainRegionRegion" table="regions" repository-class="InfrastructureRepositoriesRegionRepository">
    <id name="id" type="integer" column="id">
        <generator strategy="AUTO"/>
    </id>
    <field name="name" type="string"/>
    <field name="code" type="string"/>
    <one-to-many field="affectedRegions" target-entity="DomainAffectedRegionAffectedRegion" mapped-by="DomainMaintenanceMaintenance" />
</entity>

this is my FK:

    $affectedRegionTable->addForeignKeyConstraint(
        $regionTable,
        ['region_id'],
        ['id'],
        ['onUpdate' => 'CASCADE'],
        'fk_affectedRegions_region_id'
    );

    $affectedRegionTable->addForeignKeyConstraint(
        $regionTable,
        ['maintenance_id'],
        ['id'],
        ['onUpdate' => 'CASCADE'],
        'fk_affectedRegions_maintenance_id'
    );

the relation I want to make is:

Maintenance ← one-to-many → AffectedRegions ← many-to-one → Region

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *