Closed brandonkelly closed 5 months ago
This bug is causing craftcms/cms#15154. As far as we could tell there wasn’t a good way to workaround it, so the least-hacky thing I came up with was to override ArrayHepler::recursiveSort()
to ignore all non-associative arrays. Which is obviously not a great long-term solution since I’m effectively breaking that method.
So, hoping #20192 (or a similar fix) can get merged in and tagged in a Yii release ASAP.
What steps will reproduce the problem?
What is the expected result?
The new value will save.
What do you get instead?
The new value isn’t saved, because
ActiveRecord::isValueDifferent()
will returnfalse
forjsonColumnName
.This happens because
isValueDifferent()
normalizes each value withArrayHelper::recursiveSort()
, which sorts the array and all nested arrays using eithersort()
(if indexed) orksort
(if associative).The intent seems to be to only do this for associative arrays, which probably makes sense since the order of values is generally not important for associative arrays. But it should definitely not be happening for non-associative arrays.
https://github.com/yiisoft/yii2/blob/d9d168b036158ba2b3f139bf5155c0bb4b093d20/framework/db/BaseActiveRecord.php#L1784-L1787
Additional info