cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

beforeValidation not called before internal validation on update

Open nsossonko opened this issue 11 years ago • 4 comments

When a model is updated the beforeValidation method is not called prior to internal validation. Therefore, if a required field is not filled (or is filled with the wrong type), beforeValidation will never get called and the update fails immediately with the single internal message.

When a model is created, however, beforeValidation is called first.

nsossonko avatar Sep 25 '15 17:09 nsossonko

Just to clarify, this happens in a very specific scenario:


class Test extends \Phalcon\Mvc\Model {
  /**
   * @Column(type="integer", nullable=false, length=1)
   */
  $allow;

  public function beforeValidation() {
    echo "In beforeValidation";
  }
}

$test = new Test();
$test->allow = 0; // This is the key, the value must be empty (i.e. 0, false, etc).
$test->create();

$test->assign(array('allow' => 'a'));
$test->update(); // beforeValidation not called

nsossonko avatar Sep 25 '15 18:09 nsossonko

You could refresh the state of the model, by using $test->refresh();. It should trigger again when trying to update.

FaimMedia avatar Feb 06 '18 13:02 FaimMedia

Thank you for contributing to this issue. As it has been 90 days since the last activity, we are automatically closing the issue. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please feel free to either reopen this issue or open a new one. We will be more than happy to look at it again! You can read more here: https://blog.phalconphp.com/post/github-closing-old-issues

stale[bot] avatar May 08 '18 10:05 stale[bot]

Thank you for contributing to this issue. As it has been 90 days since the last activity, we are automatically closing the issue. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please feel free to either reopen this issue or open a new one. We will be more than happy to look at it again! You can read more here: https://blog.phalconphp.com/post/github-closing-old-issues

stale[bot] avatar Aug 06 '18 15:08 stale[bot]