Fixes in value revert logic

This commit is contained in:
2018-08-11 19:30:55 +02:00
parent 2cadbdcd31
commit 9ec5a151cc
2 changed files with 22 additions and 7 deletions
+11 -4
View File
@@ -178,7 +178,7 @@ class Changeset
*/
public function transformRow($row, $decorate)
{
if ($row instanceof Row) $row = (object)$row->getAttributes();
if ($row instanceof Row) $row = (object)$row->getAttributes(); // row must be in the rowData() format
if ($decorate) {
$row->_remove = false;
@@ -220,7 +220,12 @@ class Changeset
if ($decorate) {
$row->_changed = array_keys($newVals);
$row->_orig = array_only((array)$row, $row->_changed);
$row->_orig = array_diff((array)$row, []);
unset($row->_orig['_id']);
unset($row->_orig['_new']);
unset($row->_orig['_remove']);
unset($row->_orig['_changed']);
unset($row->_orig['_orig']);
}
$row = (object)array_merge((array)$row, $newVals);
@@ -231,6 +236,7 @@ class Changeset
if (!$decorate) {
foreach ($this->removedColumns as $colId) {
unset($row->$colId);
unset($row->_orig[$colId]);
}
}
@@ -456,9 +462,10 @@ class Changeset
$col = $cols[$colId];
$value = $col->cast($value);
$origValue = $col->cast(isset($origRow->$colId) ? $origRow->$colId : null);
$origValue = isset($origRow->$colId) ? $origRow->$colId : null;
$origValueCast = $col->cast($origValue);
if ($value !== $origValue) {
if ($value !== $origValueCast && !($origValue===null&&$value==="")) { // fix for null in numeric cols being forcibly populated and sticking as change
$updateObj[$colId] = $value;
}
}