Is it possible to know what kind(INSERT,UPDATE,DELETE) of query is going to be executed beforeSave() because there is user which can update only and other that can insert only and so on
Asked
Active
Viewed 60 times
1 Answers
2
To distinguish between an INSERT
and an UPDATE
you can check if the model's id
has been defined:-
public function beforeSave($options = array()) {
if (! empty($this->id)) {
// UPDATE
} else {
// INSERT
}
return parent::beforeSave($options);
}
If content is being deleted then beforeDelete()
is called instead of beforeSave()
.
public function beforeDelete($cascade = true) {
// DELETE
return parent::beforeDelete($cascade);
}

drmonkeyninja
- 8,490
- 4
- 31
- 59
-
1Thank you @drmonkeyninja. I completely forgot about beforeDelete() – SamGX3 May 26 '17 at 06:49