Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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;
        }
    }

}


29.3k
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'));
        }
    }
}