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

ODM setting/unsetting fields

Here is the non-working code:

class User extends \Phalcon\Mvc\Collection
{
    public $login;
    public $email;
    public $password;

    public $confirmed = false;
    public $confirmationCode;

    public function confirm()
    {
        $this->confirmed = true; // can be eliminated
        unset($this->confirmationCode);
        $this->save();
    }
}

Basic account entity, supposed to be confirmed via email. PHP unsetting as well as initializing fields some fields which weren't initialized(persisted) at first save and resaving doesn't work. Natively $set and $unset operators used in update. ODM equivalent for update is save. What is the workaround?

edited Mar '14

Nvm - Answer not relevant.



7.2k
$this->getDI()->getShared('mongo')->
            selectCollection('user')->
            update(array('_id' => $this->_id), array('$unset' => array('confirmationCode' => '')));