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

Fix soft-delete does not sync original. #24399

Closed
wants to merge 1 commit into from
Closed

Fix soft-delete does not sync original. #24399

wants to merge 1 commit into from

Conversation

Jafa80
Copy link

@Jafa80 Jafa80 commented May 31, 2018

Currently when we are soft-deleting model original is not synced. This causes an issue when model is deleted and restored without getting fresh data from database it actually stays deleted.

Here is an example of this happening in artisan:

>>> $model = App\Models\MyModel::find("HAKXFY")
=> App\Models\MyModel {#684
     id: "HAKXFY",
     created_at: "2018-05-31 15:56:13",
     updated_at: "2018-05-31 15:56:13",
     deleted_at: null,
   }
>>> $model->delete()
=> true
>>> App\Models\MyModel::find("HAKXFY")
=> null
//model is still dirty
>>> $model->getDirty();
=> [
     "updated_at" => "2018-05-31 15:58:12",
     "deleted_at" => "2018-05-31 15:58:12",
   ]
>>> $model->restore();
=> true
//Model is clean now
>>> $model->getDirty();
=> []
//While model instance thinks he's restored
>>> $model
=> App\Models\MyModel {#684
     id: "HAKXFY",
     created_at: "2018-05-31 15:56:13",
     updated_at: "2018-05-31 15:58:12",
     deleted_at: null,
   }
// Actual results from DB are different
>>> App\Models\MyModel::find("HAKXFY")
=> null
>>> App\Models\MyModel::withTrashed()->find("HAKXFY")
=> App\Models\MyModel {#689
     id: "HAKXFY",
     created_at: "2018-05-31 15:56:13",
     updated_at: "2018-05-31 15:58:12",
     deleted_at: "2018-05-31 15:58:12",
   }

When running delete and restore in same object instance delete flag will remain in database.
@taylorotwell
Copy link
Member

I am closing this pull request because it lacks sufficient explanation, tests, or both. It is difficult for us to merge pull requests without these things because the change may introduce breaking changes to the framework.

Feel free to re-submit your change with a thorough explanation of the feature and tests - integration tests are preferred over unit tests. Please include it's benefit to end users; the reasons it does not break any existing features; how it makes building web applications easier, etc.

Thanks!

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