Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Is it possible to get model without querying database?

Basicly what I want to do is run afterUpdate function of the model without fetching the data in controller, because I don't need it there. $myModel = MyModel::findFirst("id='$paramID'"); // This runs SELECT. Can I get model without this SELECT? $myModel->afterUpdate();

Is it possible to use findFirst and not fetch any data? Just get the model?

You can do this:

        $obj = new \Models\Services();

But this way you do not have any current record associated with it. With findFirst in afterUpdate you can say $this->propertyName.

If your afterUpdate is not associated with any db record i would just move it to custom function, like doSomething() and call it.


I just realized it doesn't double query the data. It was my mistake. My afterUpdate uses MyModel data. I just thought it is being fetched twice from database, but it happens only once!

Mark your last answer as correct to solve the thread and help others :)