Skip to content

Conversation

Brajk19
Copy link

@Brajk19 Brajk19 commented Sep 24, 2025

These changes enable usage of RETURNING clause for getting entity id instead of relying on another query to db.
Few conditions have to be met:

  • option should be enabled in configuration (useReturningClauseForGeneratingId)
  • entity must use strategy identity so that database creates id
  • database must support returning clause (currently im checking with instanceof, but separate PR should be opened in dbal if this solution is okay)

If conditions are met, returning clause is added to the end of insert query.

Comment on lines +1474 to +1481
/**
* This should be replaced with a method call from AbstractPlatform
*/
private function supportsReturningClause(AbstractPlatform $platform): bool
{
return $platform instanceof PostgreSQLPlatform
|| $platform instanceof MariaDb1052Platform // lowest version 10.5.0 (https://mariadb.com/kb/en/insertreturning/)
|| $platform instanceof SqlitePlatform; // lowest version 3.35.0 (https://www.sqlite.org/lang_returning.html)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separate PR in dbal should be opened for this if this gets accepted

*/
public function exists(object $entity, Criteria|null $extraConditions = null): bool;

public function usesReturningClause(): bool;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i had to add this to interface because JoinedSubclassPersister::executeInserts invokes root persister

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant