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
18
votes
2 answers

How to update FK to null when deleting optional related entity

I'm reasonably new to EF, and struggling a little to facilitate deleting my objects. My two objects and associated DbContext look as follows: public class Context: DbContext { public Context() : base(){} public DbSet Persons…
User_FSharp1123
  • 1,061
  • 1
  • 8
  • 19
17
votes
1 answer

EF4.1 Code First : How to disable delete cascade for a relationship without navigation property in dependent entity

Let's say I have these two very basic entities: public class ParentEntity { public int Id; public virtual ICollection Childrens; } public class ChildEntity { public int Id; public int ParentEntityId; // Foreign Key …
darkey
  • 3,672
  • 3
  • 29
  • 50
16
votes
3 answers

Simulate a DELETE CASCADE in MySQL?

Is it possible to predict the operations that follow a DELETE CASCADE automatically? In my software I would like to give the user a warning with details about the data that would be deleted then.
user694971
  • 421
  • 1
  • 4
  • 16
15
votes
1 answer

Fastest way to delete cascade multiple objects in Hibernate

I am using Hibernate to delete an object that has two cascade levels, and my problem is that it is VERY slow when I query for the objects and then delete and I am interested in seeing if there is a faster way. My code, which takes about 15-30…
stephen.hanson
  • 9,014
  • 2
  • 47
  • 53
15
votes
5 answers

Entity Framework on delete cascade

I have problem with deleting related rows in Entity Framework 4.1. I have tables with relations Book 1<--->* BookFormats I have set the on delete cascade: ALTER TABLE [dbo].[BookFormats] WITH CHECK ADD CONSTRAINT [FK_BookFormats_Book] FOREIGN…
Tony
  • 12,405
  • 36
  • 126
  • 226
14
votes
1 answer

Enable cascading deletes in EF Code First without exposing foreign key

When performing a delete of a one-many relationship without exposing the foreign key, EF deletes the parent record and tries to null the foreign key on the child records. This of course causes an error because the foreign key is not nullable. Adding…
Craig M
  • 5,598
  • 4
  • 32
  • 43
14
votes
1 answer

Sails.js/Waterline cascading delete for a many-to-many association

As shown in that stackoverflow answer, having no support for cascading (cascading deletes in particular) in Waterline there is a workaround for one-to-many associations by using the afterDestroy (or afterUpdate for soft-delete) lifecycle callback…
Radko Dinev
  • 865
  • 7
  • 15
14
votes
4 answers

How to enforce referential integrity on Single Table Inheritance?

I've read some of Bill Karwin's answers about single table inheritance and think this approach would be good for the setup I am considering: Playlist -------- id AUTO_INCREMENT title TeamPlaylist ------------ id REFERENCES Playlist.id teamId…
13
votes
1 answer

How to use DELETE ON CASCADE on many-to-one relation

May someone help me out. I'm trying something, but I'm (too) new to (my)SQL. I use two tables: Items and Categories. Table Items has a field with foreign key: category_id. I want the table Categories to be kept tidy. So when no item in Items is of…
Bart Weber
  • 1,136
  • 4
  • 15
  • 32
13
votes
2 answers

Problems with cascading deletion in Hibernate

This question has been asked numerous times before, yet I haven't seen a satisfactory answer since, thus I am asking it again. Imagine the following situation: public class User { ... @Cascade(value= {CascadeType.DELETE}) …
xantrus
  • 1,975
  • 1
  • 22
  • 44
13
votes
3 answers

Should I let JPA or the database cascade deletions?

Let's say we have two entities, A and B. B has a many-to-one relationship to A like follows: @Entity public class A { @OneToMany(mappedBy="a_id") private List children; } @Entity public class B { private String data; } Now, I want to…
Rasmus Franke
  • 4,434
  • 8
  • 45
  • 62
13
votes
1 answer

Which way around do cascading deletes go in a one-to-many relationship?

Using Entity Framework code-first approach. Suppose I have two entity classes: [Table("Objects")] public class DbObject : IValidatableObject { public long Id { get; set; } public string Name { get; set; } public string Description {…
Timwi
  • 65,159
  • 33
  • 165
  • 230
12
votes
2 answers

nhibernate "cascade="all-delete-orphan" error

i have 3 tables in my database: Projects (id, name) Tags (id, name) ProjectsTagss (id, projectId, tagid) As you can see the ProjectsTags table is a bridge table here is my fluent nhibernate mapping ProjectMap.cs: Map(x =>…
leora
  • 188,729
  • 360
  • 878
  • 1,366
12
votes
3 answers

What are the Pros and Cons of Cascading delete and updates?

Maybe this is sort of a naive question...but I think that we should always have cascading deletes and updates. But I wanted to know are there problems with it and when should we should not do it? I really can't think of a case right now where you…
Vishal
  • 12,133
  • 17
  • 82
  • 128
12
votes
3 answers

How to cascade on softdeletes in Laravel4?

Tried to use foreign keys with delete cascade and softDeletes without much luck. I have 2 tables: Users, Events. Both tables have softDeletes. Users can have 0..n Events. Events have an user_id, used as foreign key on users, like…
RedSash
  • 169
  • 2
  • 10
1 2
3
39 40