I want to detect if a new record was inserted or an old record was updated in afterSave(), but I have no idea how.
I thought about writing a config variable in the beforeSave() (where I can detect an insert, if the id isn’t set) but maybe that’s not a safe way of doing it.
Any ideas?
You can do it using afterSave( $model, $created ) function.
Because, the second argument of the
afterSave()function isBooleanand willtrueif a new row is created else it will gives youfalse.