-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add a test case to show #9376 and #9377 have been resolved #10733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Doctrine\Tests\ORM\Functional\Ticket; | ||
|
|
||
| use Doctrine\ORM\Mapping as ORM; | ||
| use Doctrine\ORM\Mapping\Column; | ||
| use Doctrine\ORM\Mapping\Entity; | ||
| use Doctrine\ORM\Mapping\GeneratedValue; | ||
| use Doctrine\ORM\Mapping\Id; | ||
| use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
|
||
| class GH9376Test extends OrmFunctionalTestCase | ||
| { | ||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
|
|
||
| $this->createSchemaForModels( | ||
| GH9376GiftVariant::class, | ||
| GH9376Product::class, | ||
| GH9376Gift::class | ||
| ); | ||
| } | ||
|
|
||
| public function testRemoveCircularRelatedEntities(): void | ||
| { | ||
| if (! $this->_em->getConnection()->getDatabasePlatform()->supportsForeignKeyConstraints()) { | ||
| self::markTestSkipped('Platform does not support foreign keys.'); | ||
| } | ||
|
|
||
| $product = new GH9376Product(); | ||
| $gift = new GH9376Gift($product); | ||
| $giftVariant = new GH9376GiftVariant($gift); | ||
|
|
||
| $this->_em->persist($product); | ||
| $this->_em->persist($gift); | ||
| $this->_em->persist($giftVariant); | ||
| $this->_em->flush(); | ||
| $this->_em->clear(); | ||
|
|
||
| $persistedGiftVariant = $this->_em->find(GH9376GiftVariant::class, 1); | ||
| $this->_em->remove($persistedGiftVariant); | ||
|
|
||
| $persistedGift = $this->_em->find(GH9376Gift::class, 1); | ||
| $this->_em->remove($persistedGift); | ||
|
|
||
| $this->_em->flush(); | ||
| $this->_em->clear(); | ||
|
|
||
| self::assertEmpty($this->_em->getRepository(GH9376Gift::class)->findAll()); | ||
| self::assertEmpty($this->_em->getRepository(GH9376GiftVariant::class)->findAll()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @Entity | ||
| */ | ||
| class GH9376GiftVariant | ||
| { | ||
| /** | ||
| * @var int | ||
| * @Id | ||
| * @Column(type="integer") | ||
| * @GeneratedValue | ||
| */ | ||
| public $id; | ||
|
|
||
| /** | ||
| * @ORM\ManyToOne(targetEntity=GH9376Gift::class) | ||
| * @ORM\JoinColumn(nullable=false) | ||
| * | ||
| * @var GH9376Gift | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variant points to the gift and nothing else |
||
| */ | ||
| public $gift; | ||
|
|
||
| public function __construct(GH9376Gift $gift) | ||
| { | ||
| $this->gift = $gift; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @Entity | ||
| */ | ||
| class GH9376Product | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The product points to nothing |
||
| { | ||
| /** | ||
| * @var int | ||
| * @Id @Column(type="integer") | ||
| * @GeneratedValue | ||
| */ | ||
| public $id; | ||
| } | ||
|
|
||
| /** | ||
| * @Entity | ||
| */ | ||
| class GH9376Gift | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The gif points to a product and nothing else. So the graph is like Variant -> Gift -> Product 🤔 where is the circular reference?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👀
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What a careful reader you are. Test originally comes from here: https://github.com/doctrine/orm/pull/9377/files#diff-aa92ab1b41151bbdb1e6af1f38699ad708680e99bdf4420b56b9eddd64376061 |
||
| { | ||
| /** | ||
| * @var int | ||
| * @Id @Column(type="integer") | ||
| * @GeneratedValue | ||
| */ | ||
| public $id; | ||
|
|
||
| /** | ||
| * @ORM\ManyToOne(targetEntity=GH9376Product::class) | ||
| * @ORM\JoinColumn(nullable=false) | ||
| * | ||
| * @var GH9376Product | ||
| */ | ||
| public $product; | ||
|
|
||
| public function __construct(GH9376Product $product) | ||
| { | ||
| $this->product = $product; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.