Skip to content

[9.x] Fix factory breaking when trying to determine whether a relation is empty - #45135

Merged
taylorotwell merged 1 commit into
laravel:9.xfrom
axlon:patch-45118
Nov 29, 2022
Merged

taylorotwell merged 1 commit into
laravel:9.xfrom
axlon:patch-45118

Conversation

@axlon

@axlon axlon commented Nov 29, 2022 •

Copy link
Copy Markdown
Contributor

This fixes a bug introduced in #45118. When a model's singular relation is loaded before the model is stored (e.g. in a afterMaking callback). The factory will try to call isEmpty() on it which will cause an error.

BadMethodCallException : Call to undefined method App\Models\OtherModel::isEmpty()

@WendellAdriel

Copy link
Copy Markdown
Member

@axlon that's a nice catch, I didn't expect this since it's something that was not covered in the tests.
I'm not sure if that's mandatory but I would say that adding a test case covering this issue that you fixed would be a good idea.
Also, sorry for the bug introduced with my PR 😅

@taylorotwell
taylorotwell merged commit 10a51e6 into laravel:9.x Nov 29, 2022
@axlon
axlon deleted the patch-45118 branch November 29, 2022 15:23
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