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

Can't save hasMany relation without index 0 (zero) #56

Open
bpanatta opened this issue Mar 7, 2018 · 0 comments
Open

Can't save hasMany relation without index 0 (zero) #56

bpanatta opened this issue Mar 7, 2018 · 0 comments

Comments

@bpanatta
Copy link

bpanatta commented Mar 7, 2018

As mentioned in the description of the extension, the hasMany relation array must have numerical keys:

            // has many
            [relationName] => Array 
                ( 
                    [0] => Array 
                        (
                            [relAttr] => relValue1
                        )
                    [1] => Array 
                        (
                            [relAttr] => relValue1
                        )
                )

And in the code we can see that the key 0 is required in deleteWithRelated and restoreWithRelated methods, that calls something like:
$error = !$this->{$data['name']}[0]->updateAll($this->_rt_softdelete, ['and', $array]);

I have an relation with alphanumeric keys, which doesn't have a numerical index and gives a index not defined error.
In order to solve it, I made a change to access the array data like the following:

array_values($this->{$data['name']})[0]

This approach is only valid to PHP 5.4+ though.

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