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

Optional Columns in Models

I know there are skip attributes like below. But is there an optionalAttribute() or anything? For example, if a user registers with Google+ instead of the default login form, he won't need his email so it should allow an optional value.

public function initialize()
    //Skips fields/columns on both INSERT/UPDATE operations
    // $this->skipAttributes(array('year', 'price'));

    //Skips only when inserting
    // $this->skipAttributesOnCreate(array('created_at'));

    //Skips only when updating
    // $this->skipAttributesOnUpdate(array('modified_in'));


You can mark the column as not null in the table and add a validation like this:


use Phalcon\Mvc\Model,

class Users extends Model
    public function beforeValidationOnCreate()
        if ($this->authType != "google+") {            
            $this->appendMessage(new Message(
                "Email is required",
            return false;
        return true;