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

[6.x] Fix missing statement preventing deletion #33648

Merged
merged 2 commits into from
Jul 27, 2020

Conversation

lukadriel7
Copy link
Contributor

The MorphPivot delete method was missing a statement which prevented the deletion of many to many polymorphic custom pivot models.
This pull request is related to #33647 and should fix the issue.

The delete method was missing a statement which prevented the deletion of many to many polymorphic pivot models.
@GrahamCampbell GrahamCampbell marked this pull request as draft July 25, 2020 21:23
Copy link
Member

@GrahamCampbell GrahamCampbell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test covering this?

@@ -45,6 +45,10 @@ protected function setKeysForSaveQuery(Builder $query)
*/
public function delete()
{
if (isset($this->attributes[$this->getKeyName()])) {
return (int) parent::delete();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this cast needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, To be honest, I don't know.
I just took the code from the laravel 7.x branch since the use case worked there.

MorphPivot Laravel 6.x

MorphPivot Laravel 7.x

@GrahamCampbell GrahamCampbell changed the title Fix missing statement preventing deletion [6.x] Fix missing statement preventing deletion Jul 25, 2020
@lukadriel7
Copy link
Contributor Author

Could you add a test covering this?

Sorry, I am a beginner and I really don't know how to write tests

@GrahamCampbell
Copy link
Member

@taylorotwell It looks like the original PR was #32421. I'm not sure why 7.x was targetted instead of 6.x. The author didn't explain their choice of branch, and it wasn't discussed.

@lukadriel7
Copy link
Contributor Author

Yes that's the same problem I had

@GrahamCampbell GrahamCampbell marked this pull request as ready for review July 25, 2020 23:12
@taylorotwell
Copy link
Member

So, this is just a bug fix backport?

@lukadriel7
Copy link
Contributor Author

@taylorotwell Yes, I think so

@GrahamCampbell GrahamCampbell self-requested a review July 27, 2020 08:24
@GrahamCampbell
Copy link
Member

I still don't follow why there is an int cast.

@lukadriel7
Copy link
Contributor Author

The code comes originally from the AsPivot trait

@taylorotwell taylorotwell merged commit dd00842 into laravel:6.x Jul 27, 2020
@mnaderian
Copy link

mnaderian commented Jul 31, 2020

@GrahamCampbell

I still don't follow why there is an int cast.

Maybe in case to make sure what this function is returning is int and to prevent any further exceptions.

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.

4 participants