Expected and Actual Behavior
When fetch data from db, all digital field(int, bigint, numeric etc.) treated as string(with double quotation marks, example: "99") in models. When finished business logic process, these digital values may changed to real digital value(real int or numeric in php, without double quotation marks, example: 99), then save it, will cause a db write. Actually, it shouldn't write.
SQL schema
DROP TABLE IF EXISTS `demos`;
CREATE TABLE `demos`
(
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
`flag` int(10) NOT NULL DEFAULT '1' COMMENT 'Flag',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_unicode_520_ci COMMENT ='Demos';
Provide minimal script to reproduce the issue
class Demos extends \Phalcon\Mvc\Model {
}
And there's no attributes defined in model class.
When fetch data
$row = Demos::findFirst(1);
if ( $row ) {
var_dump($row->toArray());
die();
}
will output
array(
'id' => '1',
'flag' => '99'
)
If change the flag value to 99, then save like this:
// other biz codes here
$row->flag = 99;
$row->save();
will trigger a DB write, and can get changed array via getChangedFields()
Details
- Phalcon version: 3.4.2
- PHP Version: 7.2.11
- Operating System: macOS 10.14.2
- Installation type: Compiling from source
- Zephir version (if any):
- Server: Apache
- Other related info (Database, table schema):