-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
Invalid delete query when has morphmany count relation #22413
Comments
Could you provide the code snippets as text/code in your issue instead of embedding them as images on an external site? It would make them easier to read, copy/paste, and searchable in the future. |
|
When reporting a bug, please try to post a minimal test case that reproduces your issue instead of your entire project's code. If I understand correctly, this would be the minimal code for an affected model:
Now, does the error happen when you try to delete a product through the supplier or a supplier through a product? |
When delete supplier. /api/v1/suppliers/:id |
That's just your route. What is the actual code that you're using to delete your model? I still don't know if you're trying to report a bug in the framework or asking for help with your own code. |
Simple |
In that case, I am unable to reproduce.
Could you explain what happens when you attempt to delete the supplier? Do any exceptions get thrown? |
this one |
That is quite odd. Are you overriding the |
No, it's clear |
I still can't reproduce this no matter what I try. Please run the following commands in tinker and paste the results:
|
|
I'm still unable to reproduce. Does it work if you remove the |
I remove traits and it's still not working, but when I remove withCount it's working, I said about it at report in first post. |
@36864 Is your test using softDeletes on the model? It looks like @fractalzombie is. |
@Shkeats yes, as you can see in the example I posted where my model contained the What I'm not using is the HasMedia interface, but I can't use more time trying to replicate this right now. |
I've experienced some strange behavior with 'withCount' in the past (#19388), both when using the withCount property and withCount method. These issues are possibly related. @fractalzombie downgrading to 5.3 solved the issue for me, so I'd be curious if it solves the issue you are experiencing as well. Not sure if it is feasible for you to try that though. |
@mcbanderson Can't downgrade, because project starts with 5.5 |
Please upgrade your app to the latest 5.5 release and test, if it doesn't work please include some simple steps to reproduce, you don't have to share the entire code of your project classes, just the parts that matter, not as images, but in a way we can copy/paste and test on our local machines. |
I deployed new project, and test again with $withCount and it's not working too. I include all simple steps already. download new project, and create two models, one with new morphMany relation, and try to delete than model. |
I've got the same problem. Every model that I add the withCount property and it has a polymorphic relationship, can't be deleted. Steps To Reproduce: Update |
I've tested this with latest 5.4.* and 5.5.* version (cannot test 5.6 at the moment). Steps to reproduce Fresh Laravel install with Two simple models: Article and Comment. Article with polymorphic relation and property $withCount
Create article in DB and then:
generates SQL error with following query
also $article->delete() generates similar error:
works and returns true as expected. $article->delete() generate error with following query
|
This has been fixed in 5.6. |
@staudenmeir Do you happen to know which PR/commit fixed it? Because they should probably be backported to 5.5 LTS too. |
This has been fixed in 5.5.41. |
@laurencei Can be closed. |
Thanks |
Description:
When we have morph to many relationship, we can't delete model, because it is generate invalid sql (screens are included) and delete is fails. Instead model id it gives model_type (class) from relation (??? why ???).
Steps To Reproduce:
Create model and relation model, then make relation morphMany to relation model, and then add to $withCount this relation and try to delete model.
Images:
Relation: https://ibb.co/nvDJvR
WithCount: https://ibb.co/fMwtUm
Invalid Query: https://ibb.co/e5OU26
Valid Query: https://ibb.co/gAcBFR
The text was updated successfully, but these errors were encountered: