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

Conversation

goetas
Copy link
Member

@goetas goetas commented Nov 12, 2014

No description provided.

@doctrinebot
Copy link

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DDC-3389

We use Jira to track the state of pull requests and the versions they got
included in.

@@ -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.

@Ocramius Ocramius self-assigned this Nov 12, 2014
Ocramius added a commit that referenced this pull request Nov 12, 2014
Postgres SERIAL is not a post-insert identifier generation strategy
@Ocramius Ocramius merged commit e7be0c4 into doctrine:master Nov 12, 2014
@goetas
Copy link
Member Author

goetas commented Nov 12, 2014

I think that #605 can be closed...

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.

3 participants