I have an afterFind() function in my model, I only wanted it to be run when updating the record so I did this:
public function afterFind()
// my code
However it seems that the code is also being run on a normal findAll query. I echoed out $model->scenario in my view and it is outputting ‘update’ - I definitely have not set this in my controller, so it seems like it is just defaulting to ‘update’.
Is this the intended behaviour, or have I overlooked something?
There are two default scenarios: "update" and "insert". The latter is automatically set when you create a new model. "update" scenario is set for models retrieved from a database. It frees you from defining these scenarios manually every time you create a model or retrieve models from a database.
Now you see that the scenario will always be "update" in afterFind() method. Also I doubt you need this method, because it is automatically called when a record is retrieved from a database, before you can set any scenario. What kind of task do you want to solve?