DDC422Test.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace Doctrine\Tests\ORM\Functional\Ticket;
  3. require_once __DIR__ . '/../../../TestInit.php';
  4. class DDC422Test extends \Doctrine\Tests\OrmFunctionalTestCase
  5. {
  6. protected function setUp()
  7. {
  8. parent::setUp();
  9. //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
  10. $this->_schemaTool->createSchema(array(
  11. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC422Guest'),
  12. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC422Customer'),
  13. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC422Contact')
  14. ));
  15. }
  16. /**
  17. * @group DDC-422
  18. */
  19. public function testIssue()
  20. {
  21. $customer = new DDC422Customer;
  22. $this->_em->persist($customer);
  23. $this->_em->flush();
  24. $this->_em->clear();
  25. $customer = $this->_em->find(get_class($customer), $customer->id);
  26. $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $customer->contacts);
  27. $this->assertFalse($customer->contacts->isInitialized());
  28. $contact = new DDC422Contact;
  29. $customer->contacts->add($contact);
  30. $this->assertTrue($customer->contacts->isDirty());
  31. $this->assertFalse($customer->contacts->isInitialized());
  32. $this->_em->flush();
  33. $this->assertEquals(1, $this->_em->getConnection()->fetchColumn("select count(*) from ddc422_customers_contacts"));
  34. }
  35. }
  36. /**
  37. * @Entity
  38. * @InheritanceType("JOINED")
  39. * @DiscriminatorColumn(name="discr", type="string")
  40. * @DiscriminatorMap({"guest" = "DDC422Guest", "customer" = "DDC422Customer"})
  41. */
  42. class DDC422Guest {
  43. /** @Id @Column(type="integer") @GeneratedValue */
  44. public $id;
  45. }
  46. /** @Entity */
  47. class DDC422Customer extends DDC422Guest {
  48. /**
  49. * @ManyToMany(targetEntity="DDC422Contact", cascade={"persist","remove"})
  50. * @JoinTable(name="ddc422_customers_contacts",
  51. * joinColumns={@JoinColumn(name="customer_id", referencedColumnName="id", onDelete="cascade" )},
  52. * inverseJoinColumns={@JoinColumn(name="contact_id", referencedColumnName="id", onDelete="cascade" )}
  53. * )
  54. */
  55. public $contacts;
  56. public function __construct() {
  57. $this->contacts = new \Doctrine\Common\Collections\ArrayCollection;
  58. }
  59. }
  60. /** @Entity */
  61. class DDC422Contact {
  62. /** @Id @Column(type="integer") @GeneratedValue */
  63. public $id;
  64. }