cascade="all" will always give errors, cascade={"all"} will work #1044

Closed
opened 2026-01-22 12:59:57 +01:00 by admin · 1 comment
Owner

Originally created by @daarribas on GitHub (Oct 25, 2010).

The doctrine 2.0 documentation clearly states that it is possible to use the exact statement cascade="ALL" within relationship annotations.

E.g. here: http://www.doctrine-project.org/projects/orm/2.0/docs/reference/annotations-reference/en

But when actually used like that, it will result in PHP warnings as soon as metadata is read, and the cascade will actually not be processed. This can result in all sorts of weird error conditions with error texts like "A new entity was found through a relationship that was not configured to cascade persist operations", because it will actually not respect the cascade declared.

The warnings are:

in_array() expects parameter 2 to be array, string given in ... Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 735
in_array() expects parameter 2 to be array, string given in ... Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 745
in_array() expects parameter 2 to be array, string given in ... Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 746
in_array() expects parameter 2 to be array, string given in ... Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 747
in_array() expects parameter 2 to be array, string given in ... Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 748
in_array() expects parameter 2 to be array, string given in ... Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 749

These are obviously due to this block of code in ORM/Mapping/ClassMetadataInfo:735

    // Cascades
    $cascades = isset($mapping['cascade']) ? $mapping['cascade'] : array();
    if (in_array('all', $cascades)) {
        $cascades = array(
           'remove',
           'persist',
           'refresh',
           'merge',
           'detach'
        );
    }

changing the annotation to cascade="{all"} fixes the problem, because then it is technically an array, as it would be with, say, cascade={"persist", "remove"}.

I am using the DefaultAnnotationDriver.

I consider this broken, because it does not behave as documented. More than that, the documentation actually tells people to do it wrongly.

Originally created by @daarribas on GitHub (Oct 25, 2010). The doctrine 2.0 documentation clearly states that it is possible to use the exact statement cascade="ALL" within relationship annotations. E.g. here: http://www.doctrine-project.org/projects/orm/2.0/docs/reference/annotations-reference/en But when actually used like that, it will result in PHP warnings as soon as metadata is read, and the cascade will actually not be processed. This can result in all sorts of weird error conditions with error texts like "A new entity was found through a relationship that was not configured to cascade persist operations", because it will actually not respect the cascade declared. The warnings are: in_array() expects parameter 2 to be array, string given in ... Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 735 in_array() expects parameter 2 to be array, string given in ... Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 745 in_array() expects parameter 2 to be array, string given in ... Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 746 in_array() expects parameter 2 to be array, string given in ... Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 747 in_array() expects parameter 2 to be array, string given in ... Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 748 in_array() expects parameter 2 to be array, string given in ... Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 749 These are obviously due to this block of code in ORM/Mapping/ClassMetadataInfo:735 ``` // Cascades $cascades = isset($mapping['cascade']) ? $mapping['cascade'] : array(); if (in_array('all', $cascades)) { $cascades = array( 'remove', 'persist', 'refresh', 'merge', 'detach' ); } ``` changing the annotation to cascade="{all"} fixes the problem, because then it is technically an array, as it would be with, say, cascade={"persist", "remove"}. I am using the DefaultAnnotationDriver. I consider this broken, because it does not behave as documented. More than that, the documentation actually tells people to do it wrongly.
admin closed this issue 2026-01-22 12:59:58 +01:00
Author
Owner

@beberlei commented on GitHub (Oct 31, 2010):

Can you move this issue to www.doctrine-project.org/jira ? we dont use this tracker here and i will disable it soonish.

@beberlei commented on GitHub (Oct 31, 2010): Can you move this issue to www.doctrine-project.org/jira ? we dont use this tracker here and i will disable it soonish.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1044