CodeIgniter4 icon indicating copy to clipboard operation
CodeIgniter4 copied to clipboard

fix: Entity::hasChanged() is unreliable for casts

Open kenjis opened this issue 3 years ago • 1 comments

~~Need to rebase after merging #6285~~

Description Fixes #5905

  • fix hasChanged() is unreliable for casts
  • ~~fix hasChanged() returns wrong result to mapped property~~ --> #6285

Checklist:

  • [x] Securely signed commits
  • [x] Component(s) with PHPDoc blocks, only if necessary or adds value
  • [ ] Unit testing, with >80% coverage
  • [ ] User guide updated
  • [x] Conforms to style guide

kenjis avatar Jul 21 '22 08:07 kenjis

Addendum, since most of the discussion so far has been about typing (e.g. 35 versus '35')... Entity is mildly tied to Model (not BaseModel) in that the hasChanged() methods affect database interactions. Since Model is inherently SQL-based there is an impulse to assume Entity is a representation of SQL data but I would argue that this is a big violation.

My guess is this assumption is what is mostly behind the "35 age" example we've been using: since the SQL column data type cannot change we are safe to manipulate types in developer logic. However as soon as the data source becomes collection, array store, NoSQL database, JSON file, etc... that assumption will wreak havoc.

MGatner avatar Jul 21 '22 10:07 MGatner

@kenjis What's the update here?

MGatner avatar Sep 27 '23 10:09 MGatner

Just rebased to resolve conflicts.

Since Entity is designed to have "raw data" (values retrieved from a database), it is difficult to determine if the value as PHP has changed. Raw data can change depending on the database driver and/or configuration.

kenjis avatar Sep 27 '23 21:09 kenjis

@MGatner I sent a brand new PR #7995

kenjis avatar Sep 30 '23 01:09 kenjis