Set Database Field To Id Value

I am trying re-write an already existing application, but this time based on Yii.

In the old database tables, they used a different field for primary key and according to yii db design principals, i should have an id field.

So, the question now is, when i create a new record, how do i set the value of another field in the database be the same as the primary key.

Any help will be highly appreciated.

Thanks

you can’t do that simply. Possible choices:

  1. implement afterSave and if isNewRecord == true (it will be for new records as this flag is changed after call to afterSave handler) and perform additional update in that handler.

  2. use database trigger "on insert" and put that logic there…

  3. if you use dbms with sequences (like Postgres, not MySQL with autoincrement columns) - you could manually get next sequence id and assign it to both primaryKey and that second column…

Thanks for the feedback. I guess the trigger sounds easier to do. I am going to try this and will report with feedback.