Generate unique id - doctrine - symfony2

Mitchel Verschoof picture Mitchel Verschoof · Feb 23, 2013 · Viewed 35.1k times · Source

I want to generate a unique ticket ID for my tickets. But how to let doctrine generate a unique id?

/**
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id()
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

little more explain:

  • id must be 6 charters like: 678915
  • id must be unique

Answer

Jonathan picture Jonathan · Apr 19, 2014

As of version 2.3, you can just add the following annotations to your property:

/**
 * @ORM\Column(type="guid")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="UUID")
 */
protected $id;