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

Is getChangedFields() valid?

Suppose I create a table and model like this.

CREATE TABLE tbl
(
    id      INT UNSIGNED      NOT NULL AUTO_INCREMENT,
    type    TINYINT UNSIGNED  NOT NULL DEFAULT 1,
    prefix  TINYINT UNSIGNED  NOT NULL DEFAULT 0,
    PRIMARY KEY (id),
);
INSERT INTO tbl (id, prefix) VALUES(10, 10);
class Tbls extends ModelBase
{
    protected ?int $id     = null;
    protected ?int $type   = 1;
    protected ?int $prefix = 0;
    public function getId() { return $this->id; }
    public function getType() { return $this->type; }
    public function getPrefix() { return $this->prefix; }
}

Then get the row with id = 10.

$mdl = Tbls::findFirst(10);

At this point I haven't changed anything yet, but $mdl->getChangedFields() is ['id', 'type', 'prefix'].

After executing $mdl->assign($ary), I wanted to check if there are any changed items, but this is meaningless. Each value in the snapshot was string, but the $mdl properties are integer.

Normally, all the values obtained by PDO are obtained as character strings regardless of the table settings. So, it makes sense that the snapshot value is a string, but since the property value is an integer when it is acquired by findFirst (), it is said to be "changed". I'm in trouble.

edited Sep '20

Which version of Phalcon do you use?

This problem has been fixed in versions from v4.0.0-rc.1

Issue: https://github.com/phalcon/cphalcon/issues/14376

PR: https://github.com/phalcon/cphalcon/pull/14377



4.2k
edited Sep '20

According to the result of phpinfo().

Version     4.0.6
Build Date  Jul 22 2020 12:10:21
Powered by Zephir   Version 0.12.17-6724dbf 

And

PHP Version 7.4.8
nginx/1.14.1
CentOS Linux release 8.2.2004 (Core)

PHP, nginx, Phalcon, etc. were installed using remi.

Which version of Phalcon do you use?

This problem has been fixed in versions from v4.0.0-rc.1

Issue: https://github.com/phalcon/cphalcon/issues/14376

PR: https://github.com/phalcon/cphalcon/pull/14377