i would like to implement a human-readable ID in my Doctrine-Entity. I want to keep the DB-ID for working and adding something like "PRE12-00005" (with Prefix and Year, and start at 0 every new year). I tried to add a Custom-ID-Generator, but it seems that Doctrine can't work with two generated Values in one Entity.
/**
* @var integer
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* @var string
* @ORMColumn(name="name", type="string", length=25, unique=true)
* @ORMGeneratedValue(strategy="CUSTOM")
* @ORMCustomIdGenerator(class="NameGenerator")
*/
protected $name;
Doctrine always try to save the return value from my generator into the "id"-Field and null into "name". Is there another way to implement it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…