[FLOW3-general] define auto_incement on non primary column

Peter Russ peter.russ at 4many.net
Tue Feb 7 14:30:27 CET 2012


--- Original Nachricht ---
Absender:   Peter Russ
Datum:       16.12.2011 11:26:
> --- Original Nachricht ---
> Absender: Karsten Dambekalns
> Datum: 16.12.2011 11:21:
>> Hi Peter.
>>
>> On 15.12.11 23:16, Peter Russ wrote:
>>> I have the following challenge to define an attribute which
>>> auto_increments but shouldn't be primary key. So far I haven't found a
>>> way to achive this in Doctrine.
>>>
>>> All I can figure out is that this would work with @Id and
>>> @GeneratedValue
>>> But by doing this I would loose the uuid :(
>>
>> Right, @GeneratedValue cannot be used standalone.
>>
>>> Any idea how to keep uuid and define an attribute auto_increment with
>>> Doctrine.
>>
>> You can use @Table or @Column to add a DQL snippet to add the auto
>> increment to a column used for a field, see
>> http://www.doctrine-project.org/docs/orm/2.1/en/reference/annotations-reference.html#annref-column
>>
>>
>> Regards,
>> Karsten
> Thank you Carsten, will try that!
>
> Peter

To whom it may concern:
we added @Table to class definition and @Column to the attribute.
See patch below

Index: Application/CDAS.Auth/Classes/Domain/Model/User.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- Application/CDAS.Auth/Classes/Domain/Model/User.php	(revision 396)
+++ Application/CDAS.Auth/Classes/Domain/Model/User.php	(revision )
@@ -9,6 +9,7 @@
   *
   * @FLOW3\Scope prototype
   * @FLOW3\Entity
+ * @ORM\Table(name="cdas_auth_domain_model_user", 
indexes={@ORM\index(name="igmuid_idx", columns={"igmuid"})})
   */
  class User {

@@ -58,6 +59,7 @@
  	 * The IGMUID (from IGM)
  	 * @var integer
  	 * @FLOW3\Validate(type="Integer")
+     * @ORM\Column(type="integer", columnDefinition="INT UNSIGNED NOT 
NULL AUTO_INCREMENT")
  	 */
  	protected $igmUid;

IMPORTANT you must keep @var definition or FLOW3 will ignore the column!!!

So we got Doctrine to add autoincrement to DB.
Disadvantage: columnDefinition hight depend on the database engine.
So there might be some etra work when porting to an other engine.



-- 
Fiat lux! Docendo discimus.
_____________________________
uon GbR

http://www.uon.li
http://www.xing.com/profile/Peter_Russ


More information about the FLOW3-general mailing list