yii2-audittrail
yii2-audittrail copied to clipboard
Array to String Conversion Error on array_diff() of new and old attributes
Upon saving an active record, I get a yii\base\ErrorException
of Array to string conversion
Stack trace in /var/www/html/leadworks/protected/vendor/sammaye/yii2-audittrail/LoggableBehavior.php line 101
foreach ($oldattributes as $f => $v) {
if (array_search($f, $ignoredFields) !== false)
unset($oldattributes[$f]);
}
}
// If no difference then WHY?
// There is some kind of problem here that means "0" and 1 do not diff for array_diff so beware: stackoverflow.com/questions/12004231/php-array-diff-weirdness :S
if (count(array_diff_assoc($newattributes, $oldattributes)) <= 0)
return;
// If this is a new record lets add a CREATE notification
if ($insert) {
$this->leaveTrail(self::ACTION_CREATE);
}
// Now lets actually write the attributes
$this->auditAttributes($insert, $newattributes, $oldattributes);
In Yii2, JSON fields are converted to arrays:
This needs to be accounted for in some way.