Skip to content

Commit

Permalink
Merge pull request #11768 from pbreteche/HINT_READ_ONLY-use-its-boole…
Browse files Browse the repository at this point in the history
…an-value

Check hint value before considering instance read-only
  • Loading branch information
greg0ire authored Dec 19, 2024
2 parents 9402f9e + 4a9101f commit e3cabad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -2968,7 +2968,7 @@ public function createEntity($className, array $data, &$hints = [])
$oid = spl_object_id($entity);
$this->registerManaged($entity, $id, $data);

if (isset($hints[Query::HINT_READ_ONLY])) {
if (isset($hints[Query::HINT_READ_ONLY]) && $hints[Query::HINT_READ_ONLY] === true) {
$this->readOnlyObjects[$oid] = true;
}
}
Expand Down
18 changes: 18 additions & 0 deletions tests/Tests/ORM/Functional/ReadOnlyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,24 @@ public function testReadOnlyQueryHint(): void
self::assertTrue($this->_em->getUnitOfWork()->isReadOnly($user));
}

public function testNotReadOnlyQueryHint(): void
{
$user = new ReadOnlyEntity('beberlei', 1234);

$this->_em->persist($user);

$this->_em->flush();
$this->_em->clear();

$query = $this->_em->createQuery('SELECT u FROM ' . ReadOnlyEntity::class . ' u WHERE u.id = ?1');
$query->setParameter(1, $user->id);
$query->setHint(Query::HINT_READ_ONLY, false);

$user = $query->getSingleResult();

self::assertFalse($this->_em->getUnitOfWork()->isReadOnly($user));
}

public function testNotReadOnlyIfObjectWasProxyBefore(): void
{
$user = new ReadOnlyEntity('beberlei', 1234);
Expand Down

0 comments on commit e3cabad

Please sign in to comment.