Fix #20191: Fix ActiveRecord::getDirtyAttributes() for JSON columns with multi-dimensional array values

This commit is contained in:
Brandon Kelly
2024-06-08 00:31:26 -07:00
committed by GitHub
parent 3fa2d61e54
commit 048eef42cd
3 changed files with 14 additions and 3 deletions

View File

@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.51 under development
------------------------
- Bug #20191: Fix `ActiveRecord::getDirtyAttributes()` for JSON columns with multi-dimensional array values (brandonkelly)
- Bug #20175: Fix bad result for pagination when used with GridView (@lav45)

View File

@ -1781,9 +1781,15 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
*/
private function isValueDifferent($newValue, $oldValue)
{
if (is_array($newValue) && is_array($oldValue) && ArrayHelper::isAssociative($oldValue)) {
$newValue = ArrayHelper::recursiveSort($newValue);
$oldValue = ArrayHelper::recursiveSort($oldValue);
if (is_array($newValue) && is_array($oldValue)) {
// Only sort associative arrays
$sorter = function(&$array) {
if (ArrayHelper::isAssociative($array)) {
ksort($array);
}
};
$newValue = ArrayHelper::recursiveSort($newValue, $sorter);
$oldValue = ArrayHelper::recursiveSort($oldValue, $sorter);
}
return $newValue !== $oldValue;