Skip to content

Confusing docs regarding UUID Doctrine ID Generator (service / class) - and regarding version configuration #21528

@AndreasA

Description

@AndreasA

The current documentation of the UUID doctrine ID Generator mentions the following

    #[ORM\Id]
    #[ORM\Column(type: UuidType::NAME, unique: true)]
    #[ORM\GeneratedValue(strategy: 'CUSTOM')]
    #[ORM\CustomIdGenerator(class: UuidGenerator::class)]

in https://symfony.com/doc/current/components/uid.html#storing-uuids-in-databases.

This is fine in general.

However, if one wants to use e.g. UUIDv7 this will not work, as the UUID generator creates a new class and uses its default version configuration.

Furthermore, it will not use the doctrine.uuid_generator service if the framework bundle / doctrine bundle is used.

I know this ithe documentation for the component only but if one also uses the bundle it can be confusing, as in order to use the doctrine.uuid_generator - but it also mentions the framework config - this kind of hidden documentation shows the correct syntax:

https://symfony.com/bundles/DoctrineBundle/current/custom-id-generators.html

which is:

    #[ORM\Id]
    #[ORM\Column(type: 'uuid')]
    #[ORM\GeneratedValue(strategy: 'CUSTOM')]
    #[ORM\CustomIdGenerator('doctrine.uuid_generator')]

This way the service is used, which also means the uuid version configuration.

Or alternatively add a service alias for UuidGenerator to 'doctrine.uuid_generator'?

Also, just using the service is not possible without the framework's dependency injections, so I really think there should be an option to also define the version independent of the framework bundle (which was possible previoulsy as there were multiple classes).

And also I think the note is a bit misleading against the use of UUIDs in databases, as they also have advantages and not just disadvantages.
Yes, the needed space is more but with UUIDv7 / UUIDv6 (which is used by default) the issue regarding slower due to fragmentation is not really relevant and the uniqueness of the UUIDs over multiple systems can be helpful or the use of UUIDv5 to map external IDs to an internal ID without an additional field etc. The IDs are unique over all tables (though that can be done using sequences in postgresql otherwise as well), for a lot of data it also makes not that much difference in space (as bigint might be needed otherwise), they cannot be guessed if used as route parameters or similar (which can also be an advantage, but not for security purposes).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions