cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

[bug?]Model and default value in mysql

Open Cmssspl opened this issue 13 years ago • 2 comments

Im use mysqul, example table:

id name (not null) isActive (not null, default = 1) #1

$model = new model();
$model->name = 'test';
$model->save(); // return null

#2

[...]
$model = new model();
$model->name = 'test';
$model->isActive = 1;
$model->save(); // return 1

Why #1 dont work?

Cmssspl avatar May 04 '13 21:05 Cmssspl

save() never returns "null" or "1", it returns true or false

As the column "isActive" is marked as "not null" you must tell Phalcon to use the default value explicitly by using a raw value with "default" or by skipping columns in the insert.

http://docs.phalconphp.com/en/1.1.0/reference/models.html#skipping-columns

ghost avatar May 04 '13 21:05 ghost

I do not know if it's the best solution, but get used to it. ;-)

Cmssspl avatar May 04 '13 22:05 Cmssspl