auto generate code

hello!!!

i have a feild called purchase order no in ma table. i want to auto generate the value in this field every time a purchase order is raised. how do i go about? it should not be the auto increment key. help!!

You can implement beforeSave function, for run some code each right before save.

Here you can test if ($this->isNewRecord) if you want to run some code only for creation.