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

How to define conditional cascade delete rule in Core Data?

My object graph contains two entities: Author and Book with one to many relationship (one author may write many books) I wish that when a book is deleted, the author will be deleted as well but only if there are no other books in the database…
Joshua
  • 1,974
  • 2
  • 23
  • 39
4
votes
2 answers

Is there any real advantage to managing cascading deletes in code rather than the DB?

I'm going to set up this question with some pre-conditions that may make the question irrelevant, but here goes. Assuming my database has a way to do cascading deletes and I'm not trying to code for the possible changing of DB, and my DB model is…
Michael Campbell
  • 2,022
  • 1
  • 17
  • 22
4
votes
3 answers

Django 1.2 PostgreSQL cascading delete for keys with ON DELETE NO ACTION

I have a postgresql database with about 150 tables(it's a Django 1.2 project). Django adds ON DELETE NO ACTION and ON UPDATE NO ACTION to foreign keys at the time of table creation. Now I need to bulk delete data (about 800,000 records) from a…
Mir Nazim
  • 636
  • 1
  • 8
  • 20
4
votes
1 answer

SQL command to show if table is set to cascade on delete

I need to delete some SQL Azure database entries, and I'm not sure if the cascade on delete is specified or not. If I by accident delete something important, I'm in a world of hurt. So, is there a command to check for cascade deletion?
Gleno
  • 16,621
  • 12
  • 64
  • 85
4
votes
1 answer

EF 4.1 RC: Weird Cascade Delete

I have to admit, the features of EF 4.1 RC Codefirst, DataAnnotations and FluentAPI are still overwhelming to me. Sometimes I really don't know what I am doing ;-) Please see the following POCOs: public class Country { [Key] public Guid ID {…
4
votes
0 answers

What does adding on_delete to models.py do, and what should I put in it?

The text of this answer is provided in the "duplicate question," though this goes into much more detail than any answers provided there. FYI, the on_delete parameter in models is backwards from what it sounds like. You put "on_delete" on a Foreign…
HelenM
  • 921
  • 1
  • 10
  • 14
4
votes
4 answers

NHibernate One-To-Many Delete Not Cascading

I have a 'Photo' class and a 'Comment' class. An Photo can have multiple comments assigned to it. I have this configured as a one-to-many relationship within my HBM mapping file, and have set cascade="all-delete-orphan" against the 'Comments' bag…
4
votes
1 answer

Cascade deleting from join table with @ManyToMany annotation

Hi I got a problem with mapping my entities. I'm using JPA2 and Hibernate implementation. I got tables with @ManyToMany annotation http://img204.imageshack.us/img204/7558/przykladd.png I mapped it with : @Entity @Table("employee") class Employee { …
Dawid
  • 644
  • 1
  • 14
  • 30
4
votes
1 answer

Cascading remove in JPA @OneToMany vs database cascade foreign key delete

I'm seeing a lot of similar questions, but haven't found something conclusive that brings it together. When using JPA, if you have a @OneToMany relation it can be specified to cascade the REMOVE operation. At the same time, foreign keys can be…
G_H
  • 11,739
  • 3
  • 38
  • 82
4
votes
1 answer

Doctrine 2 : ManyToOne cascade remove causes the referenced entity to be deleted

I have a setup where I have product feeds, and each feed has many products. The very simplified setup looks something like this: Feed model: /** * Class Feed represents a single feed as supplier by a supplier * @package App\Model * @Entity…
Giel Berkers
  • 2,852
  • 3
  • 39
  • 58
4
votes
1 answer

Hibernate cascade vs manual delete

I am using Hibernate and a few times had to implement cascading DELETE operation from parent object to its children. I used the following two options. One option is to expose getChildren() on the parent object, add the child to the returned…
alecswan
  • 499
  • 1
  • 6
  • 12
4
votes
2 answers

Entity Framework Cascade Delete For Inherited class

Apparently Cascade Deleting with Entity Framework is very confusing. I found lot's of questions but I have not found a solution for my problem. If I manually set the "Delete Rule" to cascade it all works. But via Fluent API I haven't found a way to…
WHOSYS
  • 65
  • 1
  • 4
4
votes
1 answer

Cascade delete using Fluent API

I have two entities. Profile and ProfileImages. After fetching a Profile I want to delete ProfileImages through Profile without it just removing the reference to Profile (setting it to null). How can this be done with fluent API and Cascading…
chuckd
  • 13,460
  • 29
  • 152
  • 331
4
votes
2 answers

Is it possible to temporarily disable cascading for a Hibernate entity?

Given a Hibernate/JPA entity with cascading set to ALL for a related entity: @Entity public class Entity { @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "entity") private Set relatedEntities; } Is…
Steve Chambers
  • 37,270
  • 24
  • 156
  • 208
4
votes
1 answer

Firebird FK on delete cascade and on update cascade trigger order

Anyone has idea why Firebird update and delete foreign key rule, work in a inverse logical? When you changes some data and it is a FK, the Firebird behavior : First: delete master After: delete details When my guess that correct behavior would…