0

I have a table USER, with an id field configured like that :

* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")

I would want that the firstName column by default would be "user12" when id=12, or "user1547" when id=1547 etc.

I know I can obtain the same result from different way (ex: in my "Entity" with the getFirstname method, or, with a second command that update firstName value etc.) but it's not my point : I need that value in the database and it must be done on the same command that the one that "insert" my new user.

Do you think it's possible ?

I guess it's possible with currval on PostgreSql with a command like :

INSERT INTO user (id, firstname, lastname) values (nextval('user_id_seq'), ('user' || currval('tmp_play_id_seq')::text), 'Smith'); 

But what about Doctrine ?

Dam Fa
  • 448
  • 4
  • 16

1 Answers1

1

If you use autogenerated value, you don't know the new ID before you save it, means you can't set your name to firstIDVALUE.

Doctrine is database agnostic, means it can't support specialised features of one database over another, and need to just use common standardised features.

So there are few solutions I see now:

M. Kebza
  • 1,488
  • 1
  • 10
  • 14