-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it possible to have non-NULLable self-referencing associations w…
…hen using application-provided IDs The change makes the `BasicEntityPersister` not schedule an extra update in the case of an entity referencing itself and having an application-provided ID (the "NONE" generator strategy). While it looks like a special corner case, the INSERTion of a NULL value plus the extra update require the self-referencing column to be defined as NULLable. This is only an issue for the self-referencing entity case. All other associations work naturally. Fixes #7877, closes #7882. Co-authored-by: Sylvain Fabre <[email protected]>
- Loading branch information
Showing
2 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
use function uniqid; | ||
|
||
/** | ||
* @group GH7877 | ||
*/ | ||
class GH7877Test extends OrmFunctionalTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->createSchemaForModels( | ||
GH7877ApplicationGeneratedIdEntity::class | ||
); | ||
} | ||
|
||
public function testSelfReferenceWithApplicationGeneratedIdMayBeNotNullable(): void | ||
{ | ||
$entity = new GH7877ApplicationGeneratedIdEntity(); | ||
$entity->id = uniqid(); | ||
$entity->parent = $entity; | ||
|
||
$this->expectNotToPerformAssertions(); | ||
|
||
$this->_em->persist($entity); | ||
$this->_em->flush(); | ||
} | ||
} | ||
|
||
/** | ||
* @ORM\Entity | ||
*/ | ||
class GH7877ApplicationGeneratedIdEntity | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="string") | ||
* @ORM\GeneratedValue(strategy="NONE") | ||
* | ||
* @var string | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity="GH7877ApplicationGeneratedIdEntity") | ||
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id", nullable=false) | ||
* | ||
* @var self | ||
*/ | ||
public $parent; | ||
} |