Stillat / relationships

Provides automated bi-directional @statamic entry relationships
MIT License
18 stars 1 forks source link

Array Key Error in OneToOne and ManyToOne #26

Closed priskahuber closed 11 months ago

priskahuber commented 1 year ago

After Update of Statamic to 4.8 (from 3.4.7) and Relationships to 2.1 i've encountered a problem with the relationships. Saving an entry brings up an "undefined array key 0" error. But only on first saving. If i saved it a second time, the error is gone. I dived into the code and found out that in "Processors/Concerns/ProcessManyToOne.php" and "Processors/Concerns/ProcessOneToOne.php" it tries to get array key 0. But in fact, this "Key" is unique (as set in "ComparisonResult.php"), so it could be 4 or 5 and so on. I've fixed it for me, but for another update, it would be nice to be fixed in your addon. That's what fixed it for me: Replace both occurencies of $results->added[0]) with $results->added[array_key_first($results->added)])

because count must be 1, you can simply check for array_key_first.

JohnathonKoster commented 11 months ago

Released as part of 2.1.2