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

Bug regarding getChangedFields and hasChanged

when you use snapshots there is a bug with null fields. It says fields doesn't changed when value is changed from null to 0. Values are compared with == not with ===. tested on 2.1 and 3.0.3 on both versions it says field doen't changed



2.7k
Accepted
answer
edited Feb '17

On line 3904 of https://github.com/phalcon/cphalcon/blob/master/phalcon/mvc/model.zep#L3904

if value != snapshot[name] {

it should be something like:

if value !== snapshot[name] {

or even it should be checked if its changed fromm null or from '' to 0 and return true and return false when from 0 to '0'

Fixed in the 3.1.x branch. Thank you.