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

How to TEMPORARILY skip column when save?

For example, I would like to skip the password column while updating if the condition of password input is empty.

CREATE TABLE user
(   id VARCHAR NOT NULL PRIMARY KEY,
    name VARCHAR NOT NULL,
    password VARCHAR NOT NULL
);
class User extends Phalcon\Mvc\Model
{   public $id;
    public $name;
    public $password;

   public function beforeUpdate() {
        if(isEmpty($this->password)){
            //skip $this->password;
        }
    }

}


40.8k
Accepted
answer

Hi, use skipAtributes method for your case

class User extends Phalcon\Mvc\Model
{   public $id;
    public $name;
    public $password;

   public function beforeUpdate() {
        if(isEmpty($this->password)){
            $this->skipAttributes(array('password'));
        }
    }
}