Questions tagged [cascading-deletes]

The concept of SQL databases deleting rows that refer (via a foreign key) to a deleted row.

The concept of SQL databases deleting rows that refer (via a foreign key) to a deleted row. The deletion is performed recursively and enabled with the ON DELETE CASCADE property of the foreign key.

587 questions
2
votes
1 answer

Code First and Cascade on Delete Errors with Simple Model

I have a simple model to keep track of locker rentals as a way to learn EF Code First and DDD principles. The model has these requirements: There may be many organizations (i.e. schools, colleges, etc.). Each organization can have many lockers and…
2
votes
1 answer

Hibernate: One To Many Relation on cascade save but doesn't delete

I have a problem with Hibernate. In Short: How to configure a ManyToMany association with Hibernate when the relationship has an attribute and we need save, delete and update in cascade? In Large: Imagine the following DataBase: Super …
ganzux
  • 874
  • 3
  • 15
  • 35
2
votes
1 answer

Hibernate @OnDelete cascade same table

I am trying to create a table which captures parent child relationships, like a tree. I would like to maintain only two columns to capture this structure "id" and "parent". I want the database to be able to cascade delete all children when a row is…
2
votes
1 answer

How to cascade deletions with Doctrine 1.2?

I have been struggling with defining cascade behavior in Doctrine ORM. According to the documentation, one is supposed to use onDelete: CASCADE for database-level cascade (which is what I am trying to achieve here). A complete example may be seen on…
MattiSG
  • 3,796
  • 1
  • 21
  • 32
2
votes
2 answers

Hibernate cascade="all-delete-orphan", doesn't delete orphans

I am having trouble deleting orphan nodes using Hibernate with the following mapping @OneToMany(fetch = FetchType.LAZY, mappedBy = "seizure",orphanRemoval=true) @JsonManagedReference @Cascade({CascadeType.ALL,CascadeType.DELETE_ORPHAN}) public…
Jeremy S.
  • 6,423
  • 13
  • 48
  • 67
2
votes
1 answer

MySQL Not allowing delete even though FK relationship ON DELETE CASCADE set

I am working on a project that makes use of a MySQL Database to store snippets of code for use on multiple websites. For each content snippet I also keep an edit history table, to which I add a record every time a snippet is updated. Occasionally it…
Brendon Dugan
  • 2,138
  • 7
  • 31
  • 65
2
votes
1 answer

How do I use SQLAlchemy to cascade deletes in SQLite?

I've been reading various examples from SQLAlchemy documentation for cascade deletes, but nothing I try seems to work. Below is some sample code adapted from that documentation, but using back_populates instead of backref, as I understand that…
M. Hearne
  • 59
  • 1
2
votes
1 answer

MySQL + Entity Framework: Can't delete object

I'm trying to delete an object that has foreign key relationships via the Entity Framework (MySQL/Connector). ClientAccount >>> ClientEmailAddresses foreach (ClientAccount client in recsClientStore.Deleted) { ClientAccount stub = new…
pierre
  • 1,235
  • 1
  • 13
  • 30
2
votes
3 answers

Delete rows from several tables in one query

What is the proper way to delete rows from several tables in one query? The reason I ask is because I am doing this with PHP. If I use multiple queries to delete from each table one at a time, PHP has to make multiple trips to the database. Will…
recount88
  • 121
  • 1
  • 3
  • 5
2
votes
2 answers

When deleting data from the pivot table, also to delete from the main table

I want to ask a question. I am developing a project in Laravel 8. I have 3 tables products (id, name), urls (id, page_id, request_id) and product_url (product_id, url_id, site_id). When a product or url is deleted, I can delete it from the…
Emre Sasi
  • 29
  • 1
  • 2
2
votes
1 answer

Django SafeDelete

I'm using the following library in my Django project https://pypi.org/project/django-safedelete/. All my models are setup for "cascading soft delete" and I'm having some trouble. One example of the problem I'm having: In my application, I have a…
Daniel N.
  • 357
  • 2
  • 20
2
votes
1 answer

Deleted object would be re-saved by cascade (remove deleted object from associations) in nhibernate

I keep getting this error when trying to delete a record from my table. Insert and Update work fine apart from delete. Here is my set up: Mappings: HasMany(x => x.Items).AsList().AsBag().LazyLoad().Cascade.AllDeleteOrphan(); GetMethod: …
Funky
  • 12,890
  • 35
  • 106
  • 161
2
votes
2 answers

Deleting rails active records with delete_all/delete violates foreign key constraint

I have an active record association setup with :dependent => :destroy, which works as intended. Then I found out I need to use delete instead of destroy due to performance, so I just changed destroy to delete_all/delete depending on the…
Lull
  • 365
  • 3
  • 14
2
votes
3 answers

Deleting from multiple tables using gridview delete command

I have a grid view utilizing sql data source. Now I want to delete a record using grid view's delete command, the problem is that a single record is based on information collected from multiple tables, so I have to delete parts of information from…
Ahmed
  • 645
  • 4
  • 13
  • 24
2
votes
1 answer

Grails reverse cascade delete without hasMany or belongsTo

I have two domain-classes. class UsersAddThese { String someData } and class TheseAreConstantlyGenerated { UsersAddThese theProblem } Is there some way to delete a UsersAddThese and automatically delete all the TheseAreConstantlyGenerated or…
Mikey
  • 4,692
  • 10
  • 45
  • 73