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

Improve soft delete mixin #290

Merged
merged 7 commits into from
Jan 6, 2021

Conversation

girardinsamuel
Copy link
Contributor

@girardinsamuel girardinsamuel commented Jan 3, 2021

Implements #276

  • only_trashed()
  • restore()
  • force_delete

@josephmancuso
Copy link
Member

the restore method should just turn the query into an update method:

should run this query:

builder.update({"deleted_at": None})

Force delete should just delete the record using a DELETE query

@josephmancuso
Copy link
Member

If you pull in 0.9 it will update some of those broken tests

@josephmancuso josephmancuso changed the base branch from 0.9 to 1.0 January 5, 2021 04:45
@josephmancuso
Copy link
Member

Changed this to be based on new 1.0 branch

@josephmancuso
Copy link
Member

Added force delete

@josephmancuso
Copy link
Member

Added restore method

Copy link
Member

@josephmancuso josephmancuso left a comment

Choose a reason for hiding this comment

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

Looks like I finished the last 2 methods required to close this ticket out! Great job!

@josephmancuso josephmancuso merged commit 1bae169 into MasoniteFramework:1.0 Jan 6, 2021
return builder.where_not_null("deleted_at")

def _force_delete(self, model, builder):
return builder.remove_global_scope(self).set_action("delete")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@josephmancuso I am just not sure to understand why we should call remove_global_scope(self) before setting action type ? it is to avoid other scope to apply so that force_delete really deletes ? If this was not there, the force_delete would be modified to an update of deleted_at with a timestamp through _query_set_null_on_delete ?

Copy link
Member

Choose a reason for hiding this comment

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

I am just not sure to understand why we should call remove_global_scope(self) before setting action type

doesn't matter which order we do it in.

builder.set_action("delete").remove_global_scope(self)

Works just as well. We do have to remove the scopes because yeah we don't want other scopes changing the action type back to update. We might not even have to set the action here, just removing the scope might actually work ..

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.

None yet

2 participants