Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array to String Conversion Error on array_diff() of new and old attributes #29

Open
dsdobrzynski opened this issue Nov 27, 2023 · 0 comments

Comments

@dsdobrzynski
Copy link

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:
image

This needs to be accounted for in some way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant