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

detach deletes the related models #760

Closed
federicoparroni opened this issue Jul 13, 2022 · 0 comments · Fixed by #762
Closed

detach deletes the related models #760

federicoparroni opened this issue Jul 13, 2022 · 0 comments · Fixed by #762
Labels
bug An existing feature is not working as intended

Comments

@federicoparroni
Copy link
Contributor

Describe the bug
In all the implementations of the detach method, the related record is always deleted:

def detach(self, current_model, related_record):
return current_model.where(
{self.local_key: getattr(related_record, self.foreign_key)}
).delete()

def detach(self, current_model, related_record):
data = {
self.local_key: getattr(current_model, self.local_owner_key),
self.foreign_key: getattr(related_record, self.other_owner_key),
}
self._table = self._table or self.get_pivot_table_name(
current_model, related_record
)
return (
Pivot.on(current_model.get_builder().connection)
.table(self._table)
.without_global_scopes()
.where(data)
.delete()
)

To my mind, this is not the expected behavior (am I wrong?), I think the proper one should be to only set the foreign key attribute to NULL.

Expected behavior
When calling detach, the related record should not be deleted.

@federicoparroni federicoparroni added the bug An existing feature is not working as intended label Jul 13, 2022
@federicoparroni federicoparroni changed the title 'detach' deletes the related models detach deletes the related models Jul 13, 2022
@josephmancuso josephmancuso mentioned this issue Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An existing feature is not working as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant