Created
March 25, 2024 15:09
-
-
Save rela589n/4abc6b61ce790057fe25dcbfa9d036e3 to your computer and use it in GitHub Desktop.
Doctrine orm Joined table inheritance LOCK FOR UPDATE
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
class ForUpdateOfTableWalker extends SqlWalker | |
{ | |
public const FOR_UPDATE_OF_TABLE = 'ForUpdateOfTable'; | |
public function walkSelectStatement(SelectStatement $AST): string | |
{ | |
$sql = parent::walkSelectStatement($AST); | |
/** @var array $hint */ | |
$hint = $this->getQuery()->getHint(self::FOR_UPDATE_OF_TABLE); | |
$tableAlias = $this->getSQLTableAlias($hint[0], $hint[1]); | |
$sql .= ' FOR UPDATE OF '.$tableAlias; | |
return $sql; | |
} | |
} | |
// Repository | |
$query = $qb->getQuery(); | |
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, ForUpdateOfTableWalker::class); | |
$query->setHint(ForUpdateOfTableWalker::FOR_UPDATE_OF_TABLE, ['abstract_entities', 'a']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment