DDC1181Test.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace Doctrine\Tests\ORM\Functional\Ticket;
  3. require_once __DIR__ . '/../../../TestInit.php';
  4. class DDC1181Test extends \Doctrine\Tests\OrmFunctionalTestCase
  5. {
  6. public function setUp()
  7. {
  8. parent::setUp();
  9. $this->_schemaTool->createSchema(array(
  10. $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1181Hotel'),
  11. $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1181Booking'),
  12. $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1181Room'),
  13. ));
  14. }
  15. /**
  16. * @group DDC-1181
  17. */
  18. public function testIssue()
  19. {
  20. $hotel = new DDC1181Hotel();
  21. $room1 = new DDC1181Room();
  22. $room2 = new DDC1181Room();
  23. $this->_em->persist($hotel);
  24. $this->_em->persist($room1);
  25. $this->_em->persist($room2);
  26. $this->_em->flush();
  27. $booking1 = new DDC1181Booking;
  28. $booking1->hotel = $hotel;
  29. $booking1->room = $room1;
  30. $booking2 = new DDC1181Booking;
  31. $booking2->hotel = $hotel;
  32. $booking2->room = $room2;
  33. $hotel->bookings[] = $booking1;
  34. $hotel->bookings[] = $booking2;
  35. $this->_em->persist($booking1);
  36. $this->_em->persist($booking2);
  37. $this->_em->flush();
  38. $this->_em->remove($hotel);
  39. $this->_em->flush();
  40. }
  41. }
  42. /**
  43. * @Entity
  44. */
  45. class DDC1181Hotel
  46. {
  47. /** @Id @Column(type="integer") @GeneratedValue */
  48. public $id;
  49. /**
  50. * @oneToMany(targetEntity="DDC1181Booking", mappedBy="hotel", cascade={"remove"})
  51. * @var Booking[]
  52. */
  53. public $bookings;
  54. }
  55. /**
  56. * @Entity
  57. */
  58. class DDC1181Booking
  59. {
  60. /**
  61. * @var Hotel
  62. *
  63. * @Id
  64. * @ManyToOne(targetEntity="DDC1181Hotel", inversedBy="bookings")
  65. * @JoinColumns({
  66. * @JoinColumn(name="hotel_id", referencedColumnName="id")
  67. * })
  68. */
  69. public $hotel;
  70. /**
  71. * @var Room
  72. *
  73. * @Id
  74. * @ManyToOne(targetEntity="DDC1181Room")
  75. * @JoinColumns({
  76. * @JoinColumn(name="room_id", referencedColumnName="id")
  77. * })
  78. */
  79. public $room;
  80. }
  81. /**
  82. * @Entity
  83. */
  84. class DDC1181Room
  85. {
  86. /** @Id @Column(type="integer") @GeneratedValue */
  87. public $id;
  88. }