Skip to content

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

Merged
taylorotwell merged 2 commits into
laravel:6.xfrom
lukadriel7:6.x
Jul 27, 2020
Merged

[6.x] Fix missing statement preventing deletion#33648
taylorotwell merged 2 commits into
laravel:6.xfrom
lukadriel7:6.x

Conversation

@lukadriel7

Copy link
Copy Markdown
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

@GrahamCampbell GrahamCampbell left a comment

Copy link
Copy Markdown
Collaborator

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?

public function delete()
{
if (isset($this->attributes[$this->getKeyName()])) {
return (int) parent::delete();

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator

@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
Copy Markdown
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
Copy Markdown
Member

So, this is just a bug fix backport?

@lukadriel7

Copy link
Copy Markdown
Contributor Author

@taylorotwell Yes, I think so

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

Copy link
Copy Markdown
Collaborator

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

@lukadriel7

Copy link
Copy Markdown
Contributor Author

The code comes originally from the AsPivot trait

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

mnaderian commented Jul 31, 2020

Copy link
Copy Markdown

@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