DDC-1181: Cascade remove doesn't work properly on entities with Identity through foreign Entities #1484

Closed
opened 2026-01-22 13:15:49 +01:00 by admin · 6 comments
Owner

Originally created by @doctrinebot on GitHub (May 30, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user sobotka:

If a collection of associated entites is marked to cascade remove and the associated entites use Identity through foreign Entities, the remove operation fails.

/****
 * @Entity
 */
class Hotel
{

    // $id column and other stuff

    /****
     * @oneToMany(targetEntity="Booking", mappedBy="hotel", cascade={"remove"})
     * @var Booking[]
     */
    private $bookings;
}

/****
 * @Entity
 */
class Booking
{
    /****
     * @var Hotel
     *
     * @Id 
     * @ManyToOne(targetEntity="Hotel", inversedBy="bookings")
     * @JoinColumns({
     *   @JoinColumn(name="hotel_id", referencedColumnName="id")
     * })
     */
    private $hotel;

    /****
     * @var Room
     *
     * @Id
     * @ManyToOne(targetEntity="Room")
     * @JoinColumns({
     *   @JoinColumn(name="room_id", referencedColumnName="id")
     * })
     */
    private $room;
}

It performs delete only for one associated entity from the collection. Other entites remain.

wampmysqld, Version: 5.5.8-log (MySQL Community Server (GPL)). started with:
TCP Port: 3306, Named Pipe: /tmp/mysql.sock
Time                 Id Command    Argument
110530 10:13:04     1 Connect   root@localhost on XXXX
            1 Query SET NAMES utf8 COLLATE utf8*czech*ci
            1 Query START TRANSACTION
            1 Query DELETE FROM booking WHERE hotel*id = '30' AND room*id = '18'
            1 Query DELETE FROM hotel WHERE id = '30'
            1 Query ROLLBACK
            1 Quit  
Originally created by @doctrinebot on GitHub (May 30, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user sobotka: If a collection of associated entites is marked to cascade remove and the associated entites use Identity through foreign Entities, the remove operation fails. ``` /**** * @Entity */ class Hotel { // $id column and other stuff /**** * @oneToMany(targetEntity="Booking", mappedBy="hotel", cascade={"remove"}) * @var Booking[] */ private $bookings; } /**** * @Entity */ class Booking { /**** * @var Hotel * * @Id * @ManyToOne(targetEntity="Hotel", inversedBy="bookings") * @JoinColumns({ * @JoinColumn(name="hotel_id", referencedColumnName="id") * }) */ private $hotel; /**** * @var Room * * @Id * @ManyToOne(targetEntity="Room") * @JoinColumns({ * @JoinColumn(name="room_id", referencedColumnName="id") * }) */ private $room; } ``` It performs delete only for one associated entity from the collection. Other entites remain. ``` wampmysqld, Version: 5.5.8-log (MySQL Community Server (GPL)). started with: TCP Port: 3306, Named Pipe: /tmp/mysql.sock Time Id Command Argument 110530 10:13:04 1 Connect root@localhost on XXXX 1 Query SET NAMES utf8 COLLATE utf8*czech*ci 1 Query START TRANSACTION 1 Query DELETE FROM booking WHERE hotel*id = '30' AND room*id = '18' 1 Query DELETE FROM hotel WHERE id = '30' 1 Query ROLLBACK 1 Quit ```
admin added the Bug label 2026-01-22 13:15:49 +01:00
admin closed this issue 2026-01-22 13:15:51 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jun 5, 2011):

Comment created by @beberlei:

Works for me, do you have a relationship between room and hotel aswell maybe?

Your model seems weird to me btw, why has booking not its own id? arent customers going to demand a booking id on their invoice?

@doctrinebot commented on GitHub (Jun 5, 2011): Comment created by @beberlei: Works for me, do you have a relationship between room and hotel aswell maybe? Your model seems weird to me btw, why has booking not its own id? arent customers going to demand a booking id on their invoice?
Author
Owner

@doctrinebot commented on GitHub (Jun 5, 2011):

Comment created by @beberlei:

Testcase that shows it works attached.

@doctrinebot commented on GitHub (Jun 5, 2011): Comment created by @beberlei: Testcase that shows it works attached.
Author
Owner

@doctrinebot commented on GitHub (Jul 26, 2011):

Comment created by @beberlei:

Lowering priority as no feedback was given.

@doctrinebot commented on GitHub (Jul 26, 2011): Comment created by @beberlei: Lowering priority as no feedback was given.
Author
Owner

@doctrinebot commented on GitHub (Jan 21, 2012):

Comment created by @beberlei:

Not reproducable and no feedback, closing issue.

@doctrinebot commented on GitHub (Jan 21, 2012): Comment created by @beberlei: Not reproducable and no feedback, closing issue.
Author
Owner

@doctrinebot commented on GitHub (Jan 21, 2012):

Issue was closed with resolution "Cannot Reproduce"

@doctrinebot commented on GitHub (Jan 21, 2012): Issue was closed with resolution "Cannot Reproduce"
Author
Owner

@doctrinebot commented on GitHub (Dec 13, 2015):

Imported 1 attachments from Jira into https://gist.github.com/2bbc06eee4b110b32e8a

@doctrinebot commented on GitHub (Dec 13, 2015): Imported 1 attachments from Jira into https://gist.github.com/2bbc06eee4b110b32e8a - [10999_DDC1181Test.php](https://gist.github.com/2bbc06eee4b110b32e8a#file-10999_DDC1181Test-php)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1484