Best way to increment column value before insert to db


What is the best way to increment column value in row before insert in Yii2? (which is not primary key - i don’t want also to use sql autoincrement). I need to get max value of one column from all rows in db before insert a new row and increment it by 1 and then assign this value to active record model field. I want this solution to be universal - where i would set only column name (i don’t want to repeat code in many models). Should it be behavior or extension or component?

Thank you for help



Override beforeSave method ( and set the specific parameter.