As I have not found a reply to this question even though I have Googled for an answer, I have to ask it here.
Can I assume that I always have ID (PK column) in $this->data[$this->alias]['id'] inside afterSave method?
If I cannot assume this, in what situation afterSave would not give PK?
Thank you for your help.
In
afterSave()you want to be using$this->idwhich is always set asafterSaveis only called if the save is successful, i.e. a row was either inserted or updated in the database.If you look at the code for
save()inModel.phpyou'll see that if the save isn't successful the method returns before theafterSavecallback is initiated.