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

Model mysteriously not saving

Hi all,

My model is refusing to save, not sure why. No error or exception gets generated. The database never sees an INSERT query either.

Model definition:


namespace Model;

class Log extends \Phalcon\Mvc\Model{

    public function beforeCreate(){
        $this->date_entered = date('Y-m-d G:i:s');
        exit('beforeCreate');
    }

    public function beforeSave(){
        exit('beforeSave');
    }
}

Table definition

Field Type Null Key Default Extra
barcode varchar(13) NO PRI
meal varchar(20) NO PRI
meal_date date NO PRI 0000-00-00
username varchar(20) YES NULL
first_name text YES NULL
last_name text YES NULL
date_entered timestamp NO CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP

Calling code

$Log             = new Log();
$Log->barcode    = 111;
$Log->meal       = 'test';
$Log->date       = date('2013-01-01 00:00:)0');
$Log->username   = 'blah';
$Log->first_name = 'Blah';
$Log->last_name  = 'McBlah';
$Log->save();


98.9k
Accepted
answer

Are messages in $Log->getMessages() after save?;

Yah - I was missing some properties - amateur stuff I would have caught if I had done any error checking.