ardent icon indicating copy to clipboard operation
ardent copied to clipboard

afterValidate hook doesn't stop saving using updateUniques() when returning false

Open mihai-scurtu opened this issue 10 years ago • 1 comments

I have the following method in my model:

public function afterValidate() {
        if(!$this->is_staff && $this->is_preview_user) {
            $this->validationErrors->add('is_preview_user', 'Only staff can be preview users');
            return false;
        }

        return true;
}

I used xdebug to walk through it, and even if it returns false the model saves just fine.

Update save() and validate() correctly return false, it's just updateUniques() that misbehaves.

mihai-scurtu avatar May 06 '15 14:05 mihai-scurtu

After some snooping around in the code, I realized that the issue is that $this->fireModelEvent('validating') returns null instead of false.

mihai-scurtu avatar May 06 '15 15:05 mihai-scurtu