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

[5.3] Fix detach behaviour (BelongsToMany.php) #16144

Closed
wants to merge 5 commits into from
Closed

[5.3] Fix detach behaviour (BelongsToMany.php) #16144

wants to merge 5 commits into from

Conversation

asamarcos
Copy link
Contributor

Change behaviour of detach.

Actual behaviour is: If it receives an empty array or collection it will erase all associations.

Example:

$houses = App\Houses::where("windows",3)->get(); //returns empty collection
$investor->houses()->detach($houses); //detaches all houses from $investor

The code above will detach all houses if $houses returns empty.

New behaviour: if it does not receive arguments, all associations are removed. If there is an argument and it is empty, no associations will be broken.

$houses = App\Houses::where("windows",3)->get(); //returns empty collection
$investor->houses()->detach($houses); //detaches nothing

Code modification checks if any $id argument was given and if it's empty, returns zero, to indicate nothing was detached.

Change behaviour of detach. Actually If it receives an empty array or collection it will erase all associations. I believe it should only break all associations if receives no argument.

Code modification checks if any $id argument was given and if it's empty, returns zero, to indicate nothing was detached.
@asamarcos asamarcos changed the title Update BelongsToMany.php [5.3] Fix detach behaviour (BelongsToMany.php) Oct 28, 2016
@taylorotwell
Copy link
Member

This would need to go to 5.4 because it is a breaking change. Please submit to master branch.

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.

2 participants