'Data marked as dirty even though it hasn't changed
Even though I'm affecting the same value to an existing field, it's being marked as dirty.
Note: The reason for direct assignment of values is because I'm importing data from an Excel file and programmatically updating rows where needed.
$request = $this->Requests->get(123);
//existing field is "ABC123"
$request->field = 'ABC123';
//field will be set as dirty, even if the content is the same
debug($request->getDirty());
Output:
[
(int) 0 => 'field',
]
Is there built-in functionality that would compare the data and not mark the field as dirty as the data didn't change? Perhaps there's an existing plugin?
Otherwise, it probably involves writing a behavior overriding beforeSave that does all of this?
Solution:
$patch = ['field' => 'ABC123'];
$request = $this->Requests->patchEntity($request, $patch);
//isDirty() is false!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
