mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-451: Add GUID/UUID Id Generator #561
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Mar 20, 2010).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user @beberlei:
We should add an IdGenerator that facilitates the DB Vendors UUID()/GUID() generation facilities.
Although these IdGenerators take more space compared to other Generators there are use-cases which can be only solved with this kind of Id Generator.
@doctrinebot commented on GitHub (Mar 20, 2010):
@doctrinebot commented on GitHub (Mar 20, 2010):
Comment created by @guilhermeblanco:
Here is a basic GUID generator.
@doctrinebot commented on GitHub (May 12, 2010):
Comment created by andyajadeh:
I agree, there are some application features that can only be done with GUID.
@doctrinebot commented on GitHub (Jul 25, 2010):
Comment created by steffenvogel:
Oh, thats a quite simple implementation of a UUID/GUID generator.
I would prefer something like this:
http://github.com/volkszaehler/volkszaehler.org/blob/master/backend/lib/Util/UUID.php
Its a RFC2144 compatible implementation for UUIDs
@doctrinebot commented on GitHub (Jul 27, 2011):
Comment created by gedrox:
Here is complete code how to do this - http://ranskills.wordpress.com/2011/05/26/how-to-add-a-custom-id-generation-strategy-to-doctrine-2-0/.
@doctrinebot commented on GitHub (Nov 23, 2011):
Comment created by maartendekeizer:
A couple of months ago I created 2 pull requests for this feature (https://github.com/doctrine/doctrine2/pull/127 and https://github.com/doctrine/dbal/pull/58). It would be nice if the feature is in the next Doctrine release.
@doctrinebot commented on GitHub (Mar 12, 2012):
Comment created by @beberlei:
Implemented
@doctrinebot commented on GitHub (Mar 12, 2012):
Issue was closed with resolution "Fixed"
@doctrinebot commented on GitHub (Mar 12, 2012):
Comment created by @beberlei:
Details: This works with Database provided GUID functionality only for now, the UUID Generator uses the AbstractPlatform#getGuidSqlExpression() function and a SELECT clause to fetch a new guid. A next step might be to add a Platform#supportsGuidGeneration() flag and otherwise fallback to a PHP based generation.
The Id generator in the ORM is pre insert, which makes this very awesome :-)
@doctrinebot commented on GitHub (Aug 7, 2012):
Comment created by marijn:
There is a nice implementation out there with proper UUID generation and a DBAL datatype.
@doctrinebot commented on GitHub (Aug 7, 2012):
Comment created by @beberlei:
starting with 2.3 there are custom id generators and you can do whatever you want. There is also a UUID/GUID type in 2.3 that is using the appropriate vendor database functions to generate those values.
@doctrinebot commented on GitHub (Aug 13, 2012):
Comment created by holtkamp:
{quote}
There is also a UUID/GUID type in 2.3 that is using the appropriate vendor database functions to generate those values.
{quote}
So how would one be able to use this UUID/GUID? Would it be required for the column to be tagged as a @Id and @GeneratedValue with GUID strategy? I would like to have a random string generated which does not act as @Id within Doctrine... The text quoted suggests that it should work out of the box by setting the column type to 'guid', which it does not (2.3.0-RC1).
Simply setting the column type to 'guid' does not trigger the database to generate an ID when INSERTing a row...
@doctrinebot commented on GitHub (Aug 13, 2012):
Comment created by @ocramius:
I'm not sure about PHP's case sensitivity, but as of
00a5f18544/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php (L310)I think you should try with "UUID" (uppercase)@doctrinebot commented on GitHub (Aug 13, 2012):
Comment created by holtkamp:
Marco, it is indeed 'UUID', but this seems not to kick in when there is no @Id annotation used. I want to use it to come up with an identifier for an Order. It is not a primary key at database level or something like that. I was just wondering whether this new functionality can be used like that. I get the feeling it is not intended to be used like this:
@doctrinebot commented on GitHub (Aug 13, 2012):
Comment created by @beberlei:
Well it is an ID generator. So it has to be with @Id.
@doctrinebot commented on GitHub (Aug 13, 2012):
Comment created by holtkamp:
Well, yes, that was my question and that is now answered, thanks.
It would be nice though to have UUID generation functionality available for non-database specific IDs as well. For instance for:
This is now something that has to be implemented at the applciation level. But since we have these generators available, why not re-use it. By adding a @Id annotation, it becomes part of a composite key, which is not the purpose. Maybe I'll dive into the code and see whether this is possible.
@doctrinebot commented on GitHub (Aug 13, 2012):
Comment created by @beberlei:
it is available, just take a look at the code.
@doctrinebot commented on GitHub (Aug 13, 2012):
Comment created by holtkamp:
{quote}Well it is an ID generator. So it has to be with @Id.{quote}
{quote}it is available, just take a look at the code.{quote}
Mmm, now I am confused, I think we are mis-communicating.
Maybe using less text and more descriptive examples:
**** without using the @Id annotations, to generate values for Entity properties that are not a primary key?
**** note that this Entity unique reference would exist next to a property that does have the @Id annotation
Attempt 1:
Attempt 2:
Based on Benjamin's first answer I guess that this is not possible. Point is, the second answer indicates that it is possible ;). What is it?
Also note that in Attempt 2, the @GeneratedValue annotation on the second property interferes with the ID generation of the Entity defined at the first property. This is probably to realize composite keys, but can result in unexpected behavior since it replaces the way the primary key is generated?
@doctrinebot commented on GitHub (Aug 13, 2012):
Comment created by @beberlei:
Well @GeneratedValue Only works with @Id as I said. But there are low level APIs that you can look up in the UuidGenerator Strategy to use for something like this.