Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@rodrigopedra
Copy link
Contributor

@rodrigopedra rodrigopedra commented Apr 22, 2025

Closes #55518

PR #55471 introduced changes to the HasRelationships@relationLoaded() to improve performance.

It introduced an oversight when loading nesting relations assuming all relations would return am iterable (e.g. Collection). That is the case for some relations, such as HasMany.

But not the case for relations such as BelongsTo, HasOne, MorphOne, which return a single model.

So when iterating one of these relations, the foreach works iterating through the Model instance public properties such as incrementing, exists, ...

This PR:

  • Ensure the relation is iterable before iterating the affected foreach
  • Add a test case

@danharrin
Copy link
Contributor

This does solve #55518, but personally I think you should add a new test case to ensure that this doesn't regress

@rodrigopedra
Copy link
Contributor Author

@danharrin thanks for reviewing it.

I just added a test case

@taylorotwell taylorotwell merged commit 63b4d72 into laravel:12.x Apr 23, 2025
58 checks passed
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.

Update to relationLoaded() causes problems when accessing attributes on a model containing a period

5 participants