Skip to content
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

Postgres SERIAL is not a post-insert identifier generation strategy #1184

Merged
merged 1 commit into from
Nov 12, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/ORMException.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function entityMissingForeignAssignedId($entity, $relatedEntity)
"Entity of type " . get_class($entity) . " has identity through a foreign entity " . get_class($relatedEntity) . ", " .
"however this entity has no identity itself. You have to call EntityManager#persist() on the related entity " .
"and make sure that an identifier was generated before trying to persist '" . get_class($entity) . "'. In case " .
"of Post Insert ID Generation (such as MySQL Auto-Increment or PostgreSQL SERIAL) this means you have to call " .
"of Post Insert ID Generation (such as MySQL Auto-Increment) this means you have to call " .
Copy link
Member

Choose a reason for hiding this comment

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

Serial is actually one, since we insert the record and read the last insert id for the current session. The fact that it is backed by a sequence is a different story.

Copy link
Member Author

Choose a reason for hiding this comment

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

we insert the record and read the last insert id for the current session.

This is not true, the persist() call will call the DB and get the next available ID, later an insert will be performed using the obtained ID

Copy link
Member

Choose a reason for hiding this comment

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

That's when using a sequence explicitly. SERIAL is using a sequence implicitly. I'm looking at Doctrine\ORM\Id\IdentityGenerator

When using SERIAL fields, then this generator is being used, whereas using a sequence explicitly causes the Doctrine\ORM\Id\SequenceGenerator to be used.

Copy link
Member

Choose a reason for hiding this comment

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

Blah, nvm, my fault, found that Doctrine\ORM\Mapping\ClassMetadataFactory is true for Doctrine\DBAL\Platforms\PostgreSqlPlatform, so the sequence name is extracted in any case when using SERIAL columns (and ClassMetadata::GENERATOR_TYPE_AUTO), and a sequence generator is used.

Merging.

"EntityManager#flush() between both persist operations."
);
}
Expand Down