-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
Improve automatic detaching / deletion of relations #156
Conversation
@xyzqtc @arvislacis welcome to join the discussion |
I tested this with success on a model with a |
@arvislacis do you mind creating a PR in the main winter repo to address the issue I mentioned in this PR description? Thanks! |
@mjauvin I added wintercms/winter#972 PR but it's not working for me - delete_at column is not being updated when deleting User and columns are fully deleted from |
@arvislacis did you properly copy the SoftDelete trait from my PR to your local storm folder? |
@mjauvin I am pretty sure I did, I copied full RAW file of this PR to my local copy. But I will re-check this tomorrow. |
And how did you verify it's not working exactly ? |
@mjauvin Some updates on this:
"How did you verify it's not working exactly" - I verified it as described in wintercms/winter#386 (comment) - create new user or add existing user (non default admin) to group, then delete the user, then restore user with WinterCMS admin UI - result is that restored user entry has no group relationships. |
@mjauvin I did some further debugging but unfortunately didn't find root cause of pivot table relationship being still deleted - it looks like that after the Anyways, I would suggest to repeat user deletion and restoration operations with WinterCMS back-end as described here: wintercms/winter#386 (comment) |
@arvislacis I found the problem, the Backend User model extends Storm's Auth/User model which has a afterDelete method shown below: /**
* Delete the user groups
* @return void
*/
public function afterDelete()
{
if ($this->hasRelation('groups')) {
$this->groups()->detach();
}
} |
|
Actually, we might want to remove that @LukeTowers or @bennothommo can you confirm that we should remove the afterDelete method in |
@mjauvin Nice find! I can confirm that applying the latest changes fixes the wintercms/winter#386 For me it looks like |
Yeah, I made a fix to the base Model class so that the afterDelete method is not required anymore |
LGTM! @bennothommo any final thoughts? |
@bennothommo I added the hard delete tests you requested. |
@LukeTowers @mjauvin As this is merged now, what about related PR and issue in winter repo? |
What do you mean exactly? |
I mean merging also wintercms/winter#972 and closing wintercms/winter#386 or it will be done with WinterCMS 1.4 release? |
Yes, theee should be merged and closed soon. |
Fixes #386. Related: wintercms/storm#156 PR
Fixes #386. Related: wintercms/storm#156 PR
First step in Fixing wintercms/winter#386
Related to wintercms/winter#972
When deleting/soft-deleting & restoring a model relations, we need a separate case for relations using a pivot table.