From d3ab9b51fad3b99b13c257d43a513a1c02b62b95 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 5 Jun 2011 13:57:44 +0200 Subject: [PATCH] DDC-1181 - Add test that verifies cascade remove works for entities with foreign identifiers --- .../ORM/Functional/Ticket/DDC1181Test.php | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php new file mode 100644 index 000000000..225353034 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1181Test.php @@ -0,0 +1,101 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1181Hotel'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1181Booking'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1181Room'), + )); + } + + /** + * @group DDC-1181 + */ + public function testIssue() + { + $hotel = new DDC1181Hotel(); + $room1 = new DDC1181Room(); + $room2 = new DDC1181Room(); + + $this->_em->persist($hotel); + $this->_em->persist($room1); + $this->_em->persist($room2); + $this->_em->flush(); + + $booking1 = new DDC1181Booking; + $booking1->hotel = $hotel; + $booking1->room = $room1; + $booking2 = new DDC1181Booking; + $booking2->hotel = $hotel; + $booking2->room = $room2; + $hotel->bookings[] = $booking1; + $hotel->bookings[] = $booking2; + + $this->_em->persist($booking1); + $this->_em->persist($booking2); + $this->_em->flush(); + + $this->_em->remove($hotel); + $this->_em->flush(); + } +} + +/** + * @Entity + */ +class DDC1181Hotel +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + + /** + * @oneToMany(targetEntity="DDC1181Booking", mappedBy="hotel", cascade={"remove"}) + * @var Booking[] + */ + public $bookings; + +} + +/** + * @Entity + */ +class DDC1181Booking +{ + /** + * @var Hotel + * + * @Id + * @ManyToOne(targetEntity="DDC1181Hotel", inversedBy="bookings") + * @JoinColumns({ + * @JoinColumn(name="hotel_id", referencedColumnName="id") + * }) + */ + public $hotel; + /** + * @var Room + * + * @Id + * @ManyToOne(targetEntity="DDC1181Room") + * @JoinColumns({ + * @JoinColumn(name="room_id", referencedColumnName="id") + * }) + */ + public $room; +} + +/** + * @Entity + */ +class DDC1181Room +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; +} \ No newline at end of file