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

4.0版本,联合主键save时报错Cannot access offset of type array on array #673

Open
cs99619 opened this issue Feb 18, 2025 · 1 comment

Comments

@cs99619
Copy link

cs99619 commented Feb 18, 2025

经跟踪src/Model.php文件941行错误
将原来代码

        if ($this->key) {
            $where = [$pk => $this->key];
        } elseif (is_string($pk) && isset($this->origin[$pk])) {
            $where     = [$pk => $this->origin[$pk]];
            $this->key = $this->origin[$pk];
        } elseif (is_array($pk)) {
            foreach ($pk as $field) {
                if (isset($this->origin[$field])) {
                    $where[] = [$field, '=', $this->origin[$field]];
                }
            }
        }

修改为:

        if ($this->key) {
            if (is_array($this->key)) {
                foreach ($this->key as $field) {
                    if (isset($this->origin[$field])) {
                        $where[] = [$field, '=', $this->origin[$field]];
                    }
                }
            } else {
                $where = [$pk => $this->key];
            }
        } elseif (is_string($pk) && isset($this->origin[$pk])) {
            $where     = [$pk => $this->origin[$pk]];
            $this->key = $this->origin[$pk];
        } elseif (is_array($pk)) {
            foreach ($pk as $field) {
                if (isset($this->origin[$field])) {
                    $where[] = [$field, '=', $this->origin[$field]];
                }
            }
        }
@rena-ertam028
Copy link

AI tried to solve the issue:

When model has composite primary keys, the key property can be an array. Current code only handles scalar keys. This fix adds proper handling for array keys by iterating through the key array and building where conditions for each key field.

The key array should be handled similarly to how array primary keys are handled - by building an array of conditions for each field.

You can review changes in this commit: rena-ertam028@cfa1787.

Caution

Disclaimer: The concept of solution was created by AI and you should never copy paste this code before you check the correctness of generated code. Solution might not be complete, you should use this code as an inspiration only.


Latta AI seeks to solve problems in open source projects as part of its mission to support developers around the world. Learn more about our mission at https://latta.ai/ourmission . If you no longer want Latta AI to attempt solving issues on your repository, you can block this account.

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

2 participants