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

[automatic validation] save() === false but data inserted in db

Hi, I have a table with not null field 'type' who have a default value in the mysql, when I try to save the object with save() it returns false with this error message : type is required. but the data is inserted in the db !!!!!

Is it a bug ? and how to tell phalcon not to validate empty required fields that have default values without turning off 'notNullValidations'

Also, devtools generate a method in the models email validation for every field named 'email', without taking in concidiration that this field is not required, and its preventing me from saving (for real this time) even if the email field can be null in the db, so I have to remove this method each time I generate the models. Is there a clean way to stop devtools from making it, or to change the EmailValidator behavior so it doesn't validate empty fields?

Field | Type | Null | Default 
...

type | tinyint(1) unsigned | NO | 0 

email | varchar(45) |YES |NULL  
...
  • Phalcon version: 3.2.2
  • devtools version: 3.2.3
  • PHP Version: 7.0.22
  • Operating System: Ubuntu 16.04.1
  • Database: MySQL 5.7

First try this:

    <?php
    class User extends Model {
        public function initialize() {
            // Should only update fields that were changed
            $this->useDynamicUpdate(true);
        }
    }

If that does not fix the create method, see Skipping Columns and you could add one for the save method:

    <?php
    class User extends Model {
        public function initialize() {
            // Should only update fields that were changed
            $this->useDynamicUpdate(true);

             // Skips only when inserting
            $this->skipAttributesOnCreate([
                'yourFieldHere',
            ]);
        }
    }