We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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();
        $obj->afterUpdate();

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.



7.4k
Accepted
answer

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 :)