1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
<?php
declare(strict_types=1);
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\DiscriminatorColumn;
use Doctrine\ORM\Mapping\DiscriminatorMap;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\InheritanceType;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\JoinTable;
use Doctrine\ORM\Mapping\ManyToMany;
use Doctrine\ORM\PersistentCollection;
use Doctrine\Tests\OrmFunctionalTestCase;
use function get_class;
class DDC422Test extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();
$this->createSchemaForModels(
DDC422Guest::class,
DDC422Customer::class,
DDC422Contact::class
);
}
/** @group DDC-422 */
public function testIssue(): void
{
$customer = new DDC422Customer();
$this->_em->persist($customer);
$this->_em->flush();
$this->_em->clear();
$customer = $this->_em->find(get_class($customer), $customer->id);
self::assertInstanceOf(PersistentCollection::class, $customer->contacts);
self::assertFalse($customer->contacts->isInitialized());
$contact = new DDC422Contact();
$customer->contacts->add($contact);
self::assertTrue($customer->contacts->isDirty());
self::assertFalse($customer->contacts->isInitialized());
$this->_em->flush();
self::assertEquals(1, $this->_em->getConnection()->fetchOne('select count(*) from ddc422_customers_contacts'));
}
}
/**
* @Entity
* @InheritanceType("JOINED")
* @DiscriminatorColumn(name="discr", type="string")
* @DiscriminatorMap({"guest" = "DDC422Guest", "customer" = "DDC422Customer"})
*/
class DDC422Guest
{
/**
* @var int
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
public $id;
}
/** @Entity */
class DDC422Customer extends DDC422Guest
{
/**
* @var Collection<int, DDC422Contact>
* @ManyToMany(targetEntity="DDC422Contact", cascade={"persist","remove"})
* @JoinTable(name="ddc422_customers_contacts",
* joinColumns={@JoinColumn(name="customer_id", referencedColumnName="id", onDelete="cascade" )},
* inverseJoinColumns={@JoinColumn(name="contact_id", referencedColumnName="id", onDelete="cascade" )}
* )
*/
public $contacts;
public function __construct()
{
$this->contacts = new ArrayCollection();
}
}
/** @Entity */
class DDC422Contact
{
/**
* @var int
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
public $id;
}
|