mirror of
				https://github.com/yiisoft/yii2.git
				synced 2025-10-31 10:39:59 +08:00 
			
		
		
		
	Fix #20191: Fix ActiveRecord::getDirtyAttributes() for JSON columns with multi-dimensional array values
				
					
				
			This commit is contained in:
		| @ -4,6 +4,7 @@ Yii Framework 2 Change Log | |||||||
| 2.0.51 under development | 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) | - Bug #20175: Fix bad result for pagination when used with GridView (@lav45) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | |||||||
| @ -1781,9 +1781,15 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface | |||||||
|      */ |      */ | ||||||
|     private function isValueDifferent($newValue, $oldValue) |     private function isValueDifferent($newValue, $oldValue) | ||||||
|     { |     { | ||||||
|         if (is_array($newValue) && is_array($oldValue) && ArrayHelper::isAssociative($oldValue)) { |         if (is_array($newValue) && is_array($oldValue)) { | ||||||
|             $newValue = ArrayHelper::recursiveSort($newValue); |             // Only sort associative arrays | ||||||
|             $oldValue = ArrayHelper::recursiveSort($oldValue); |             $sorter = function(&$array) { | ||||||
|  |                 if (ArrayHelper::isAssociative($array)) { | ||||||
|  |                     ksort($array); | ||||||
|  |                 } | ||||||
|  |             }; | ||||||
|  |             $newValue = ArrayHelper::recursiveSort($newValue, $sorter); | ||||||
|  |             $oldValue = ArrayHelper::recursiveSort($oldValue, $sorter); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return $newValue !== $oldValue; |         return $newValue !== $oldValue; | ||||||
|  | |||||||
| @ -28,6 +28,10 @@ abstract class BaseActiveRecordTest extends DatabaseTestCase | |||||||
|                 ['pineapple' => 2, 'apple' => 5, 'banana' => 1], |                 ['pineapple' => 2, 'apple' => 5, 'banana' => 1], | ||||||
|                 ['pineapple' => 2, 'apple' => 3, 'banana' => 1], |                 ['pineapple' => 2, 'apple' => 3, 'banana' => 1], | ||||||
|             ], |             ], | ||||||
|  |             'multi-dimensional array' => [ | ||||||
|  |                 ['foo' => ['c', 'b', 'a']], | ||||||
|  |                 ['foo' => ['b', 'c', 'a']], | ||||||
|  |             ], | ||||||
|  |  | ||||||
|             'filling an empty array' => [ |             'filling an empty array' => [ | ||||||
|                 [], |                 [], | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Brandon Kelly
					Brandon Kelly