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

Fatal error while updating database records

Hi All,

I am trying to update each record inside database this way

    $allUsers = Users::find([
         'columns'   => 'user_name'
     ]);
     foreach ($allUsers as $user){
         $this->tokenHash = $this->generateToken();
         $this->token = $this->userName.'|'.$this->tokenHash;
        $user->update([
             'token'         => $this->token,
             'token_hash'    => $this->tokenHash
         ]);
     }

But, a fatal error happens when trying to update the records:

Fatal error: Uncaught Error: Call to undefined method Phalcon\Mvc\Model\Row::save()

Any ideas ?



77.7k
Accepted
answer
edited Feb '18

You are only querying one column, user_name, so the ORM does not build a full Users model instance, only a Row.

Just issue $allUsers = Users::find();

Thank alot, it's working fine now.