-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fix entity refresh after cleared em #10362
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Models\GH10336; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity | ||
* @ORM\Table(name="gh10336_entities") | ||
*/ | ||
class GH10336Entity | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer") | ||
* @ORM\GeneratedValue | ||
*/ | ||
public ?int $id = null; | ||
|
||
/** | ||
* @ORM\ManyToOne(targetEntity="GH10336Relation") | ||
* @ORM\JoinColumn(name="relation_id", referencedColumnName="id", nullable=true) | ||
*/ | ||
public ?GH10336Relation $relation = null; | ||
} |
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,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Models\GH10336; | ||
|
||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity | ||
* @ORM\Table(name="gh10336_relations") | ||
*/ | ||
class GH10336Relation | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer") | ||
* @ORM\GeneratedValue | ||
*/ | ||
public ?int $id = null; | ||
|
||
/** | ||
* @ORM\Column(type="string") | ||
*/ | ||
public string $value; | ||
} |
44 changes: 44 additions & 0 deletions
44
tests/Doctrine/Tests/ORM/Functional/Ticket/GH10336Test.php
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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket; | ||
|
||
use Doctrine\Tests\Models\GH10336\GH10336Entity; | ||
use Doctrine\Tests\Models\GH10336\GH10336Relation; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
/** | ||
* @requires PHP 7.4 | ||
*/ | ||
final class GH10336Test extends OrmFunctionalTestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->createSchemaForModels( | ||
GH10336Entity::class, | ||
GH10336Relation::class | ||
); | ||
} | ||
|
||
public function testCanAccessRelationPropertyAfterClear(): void | ||
{ | ||
$relation = new GH10336Relation(); | ||
$relation->value = 'foo'; | ||
$entity = new GH10336Entity(); | ||
$entity->relation = $relation; | ||
|
||
$this->_em->persist($entity); | ||
$this->_em->persist($relation); | ||
$this->_em->flush(); | ||
$this->_em->clear(); | ||
|
||
$entity = $this->_em->find(GH10336Entity::class, 1); | ||
|
||
$this->_em->clear(); | ||
|
||
$this->assertSame('foo', $entity->relation->value); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Straight forward solution coming into my mind first but really not the most elegant one. A pity the already available field mapping of
ClassMetadataInfo
cannot be used. It just misses a few information like private visibility of the properties.Another much easier fix could be to make sure the identifier is in the skip array after the loop. If this is not the case we should be able to consider it private and therefor have all information to add it. All other private properties of parent classes should not matter anyway, if I got that correctly.