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.
you can’t do that simply. Possible choices:
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.
use database trigger "on insert" and put that logic there…
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.