doctrine / orm

Doctrine Object Relational Mapper (ORM)
https://www.doctrine-project.org/projects/orm.html
MIT License
9.93k stars 2.51k forks source link

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

Closed doctrinebot closed 8 years ago

doctrinebot commented 13 years ago

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  
doctrinebot commented 13 years ago

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 13 years ago

Comment created by @beberlei:

Testcase that shows it works attached.

doctrinebot commented 13 years ago

Comment created by @beberlei:

Lowering priority as no feedback was given.

doctrinebot commented 12 years ago

Comment created by @beberlei:

Not reproducable and no feedback, closing issue.

doctrinebot commented 12 years ago

Issue was closed with resolution "Cannot Reproduce"

doctrinebot commented 8 years ago

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