-
Notifications
You must be signed in to change notification settings - Fork 11.3k
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
[5.4] Eloquent save-query with protected $withCount eager load on polymorphic relation fails #20640
Comments
Having the exact same issue. |
Me too. (Laravel 5.5) |
@themsaid Any chance to look into this issue please? |
This is fixed in a recent PR |
Awesome, thanks @themsaid ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description:
Updating an Eloquent model with a default withCount eager load on a polymorphic relation fails.
Steps To Reproduce:
MYSQL query:
UPDATE ... where
id= App\Post
Failing Test:
(I'm happy to PR a failing test if it makes things easier)
In DatabaseEloquentIntegrationTest:
Add a withCount to the model: photos relation is polymorphic.
Try to update any attribute of that model.
MySQL will give the following error:
The query contains a strange condition:
where "id" = Illuminate\Tests\Database\EloquentTestPostWithPhotosCount
Steps To Work Around The Problem:
By not using
protected $withCount = ['photos'];
and only calling it via$query->withCount('photos')
.However as this
$withDefault
property exists on the model class, I would assume it would work with updating the model as well. For my specific use-case I can work around it, but it toke me a while to figure out why my model didn't update.Possible solution
Remove the
->with()
and->withCount()
when it's asave()
query: this fixes this use-case.I tried doing this as a PR, but a lot of tests fail; I'm not sure of the impact of this.
The text was updated successfully, but these errors were encountered: