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.

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();


85.3k
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.