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

Fixed Undefined Key error in nested relationship #547

Merged
merged 1 commit into from
Feb 11, 2022

Conversation

kohlerdominik
Copy link

Hello there

When using nested, optional relationships (which might be quite an edge case) there is a small possibility that the library is throwing an error.

It is correctly described in the comment above the problematic line, that The first model in the array is always the parent. This can be retrieved in most cases by index 0.

BUT, if the previously called filter in Illuminate/Database/Eloquent/Collection.php:227 happens to filter the model with index 0 (which is perfectly possible, as otherwise the filter would be unnecessary), then we have an Undefined array key 0 error.

Therefore, I propose to change the given implementation to use reset() to get the first model, as this truly returns the first model in the array rather than the model with index 0.

@lazychaser lazychaser merged commit 3fe245b into lazychaser:v5 Feb 11, 2022
@emielmolenaar
Copy link
Contributor

Thanks for merging this. This fix is in the v5 branch, but not the v6 branch. Is there a specific reason for that?

@kohlerdominik
Copy link
Author

Hi @emielmolenaar

Didn't realize that there's a v6 branch. I created a PR to merge the same commit to this branch: #552

@emielmolenaar
Copy link
Contributor

@kohlerdominik All right, nice! Thanks for the PR. Hoping to see that one merged soon 😃

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

Successfully merging this pull request may close these issues.

3 participants