We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.


Hi, I have this code in my model:

protected function beforeCreate() {
    $subs = $this->findFirst("user_id = $this->user_id AND to_id = $this->to_id AND type = $this->type");
    if ($subs)

And it really checks to see if such a record already and call skipOperation(); Nevertheless, the operation is still running.

What am I doing wrong?

edited Nov '14

I think you're wrong, method findFirst is static so you can not call this, try this


No, it's working properly. I test all in xdebug and if row exist, then call skipOperation, but insert still occurs.

@phalcon, can you help me?


skipOperation is only intended to work with the 'delete' operation right now, rather than that you can return false to stop the current operation.


Also, your code is prone to SQL injections, consider use bound paramters.

edited Dec '14

Ok, about injections, but if I return false, then i need something like this:

if (!$notySubs->save() && array_key_exists(0, $notySubs->getMessages()))
    throw new ErrorException($notySubs->getMessages());

It's no good :( Can you extend skipOperation for all CRUD operations in next release?


skipOperation does not make what you think it does, it just changes the current operation from 'delete' to 'update'

But it is not logical, well, or at least I would like to see it differently :)

Okay, I do not insist, but such a thing still could be useful not only for me.