I want to make an check to make sure the correct datatype is received to update the database with.

I tried this:

use Phalcon\Mvc\Model\Validator\Numericality as NumericalityValidator;

class LevelCategories extends \Phalcon\Mvc\Model {

     * @var integer
    public $id;

     * @var string
    public $name;

     * Initialize method for model.
    public function initialize() {
        $this->hasMany('id', 'Levels', 'category_id', 
                    "alias" => "levels",
                    "foreignKey" => array(
                        "message" => "The category cannot be deleted because other levels are using it"

    public function validation() {
        $this->validate(new NumericalityValidator(array(
            "field" => 'id',
            "message" => "The id must be numeric"
        if ($this->validationHasFailed() == true) {
            return false;


I tried this to get the error:

$category = LevelCategories::findFirst();
$category->id = "a string";
if ($instance->update() == false) {
        $messages = array();
        foreach ($instance->getMessages() as $message) {
            array_push($messages, (string) $message);
        echo implode("<br>", $messages);

The response I got was: id is required Which is of type "PresenceOf"

Most probably it triggers because the id value doesnt exist because it is invalid. But I want to get the error that the id must be numeric

Additional information:

PHP Version 5.5.9

Phalcon Version 2.0.10 Powered by Zephir Version 0.9.2a-dev