cascading-deletes

MS SQL “ON DELETE CASCADE” multiple foreign keys pointing to the same table?

巧了我就是萌 提交于 2019-11-26 18:13:29
问题 Howdy, I have a problem where i need a cascade on multiple foreign keys pointing to the same table.. [Insights] | ID | Title | | 1 | Monty Python | | 2 | Spamalot | [BroaderInsights_Insights] | broaderinsight_id | insight_id | | 1 | 2 | Basically when either record one or two in the insights table is deleted i need the relationship to also be deleted.. I've tried this: CREATE TABLE broader_insights_insights(id INT NOT NULL IDENTITY(1,1), broader_insight_id INT NOT NULL REFERENCES insights(id)

JPA 2.0 orphanRemoval=true VS on delete Cascade

不羁岁月 提交于 2019-11-26 16:58:14
I am a little confused about the JPA 2.0 orphanRemoval attribute. I think I can see its is needed when I use my JPA provider's DB generation tools to create the underlying database DDL to have an ON DELETE CASCADE on the particular relation. However, if the DB exists and it already has an ON DELETE CASCADE on the relation, is this not enough to cascade the deletion appropriately? What does the orphanRemoval do in addition? Cheers axtavt orphanRemoval has nothing to do with ON DELETE CASCADE . orphanRemoval is an entirely ORM-specific thing . It marks "child" entity to be removed when it's no

Django - Cascade deletion in ManyToManyRelation

为君一笑 提交于 2019-11-26 16:50:20
问题 Using the following related models (one blog entry can have multiple revisions): class BlogEntryRevision(models.Model): revisionNumber = models.IntegerField() title = models.CharField(max_length = 120) text = models.TextField() [...] class BlogEntry(models.Model): revisions = models.ManyToManyField(BlogEntryRevision) [...] How can I tell Django to delete all related BlogEntryRevision s when the corresponding BlogEntry is deleted? The default seems to be to keep objects in a many-to-many

How do I edit a table in order to enable CASCADE DELETE?

折月煮酒 提交于 2019-11-26 14:29:07
问题 I have a table representing users. When a user is deleted I get: DELETE statement conflicted with the REFERENCE constraint Apparently, CASCADE DELETE is not as easy as I imagined in SQL Server, and the option needs to be added to the table. The problem is: I cannot figure out how to add the CASCADE DELETE option. I'm using: SQL Server 2008 . Any ideas how to do this? 回答1: Read this Microsoft article first. Read Me. I use the GUI during design so here is a picture of how it is selected in SSMS

On delete cascade with doctrine2

吃可爱长大的小学妹 提交于 2019-11-26 11:30:58
I'm trying to make a simple example in order to learn how to delete a row from a parent table and automatically delete the matching rows in the child table using Doctrine2. Here are the two entities I'm using: Child.php: <?php namespace Acme\CascadeBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="child") */ class Child { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @ORM\ManyToOne(targetEntity="Father", cascade={"remove"}) * * @ORM\JoinColumns({ * @ORM\JoinColumn(name="father_id",

How do you ensure Cascade Delete is enabled on a table relationship in EF Code first?

大城市里の小女人 提交于 2019-11-26 10:35:42
问题 I would like to enable CASCADE DELETE on a table using code-first. When the model is re-created from scratch, there is no CASCADE DELETE set even though the relationships are set-up automatically. The strange thing is that it DOES enable this for some tables with a many to many relationship though, which you would think it might have problems with. Setup: Table A <- Table B. Table B\'s FK points to Table A\'s PK. Why would this not work? 回答1: Possible reason why you don't get cascading delete

Entity Framework 4.1 InverseProperty Attribute and ForeignKey

独自空忆成欢 提交于 2019-11-26 09:33:03
问题 I will create two references between Employee and Team entities with foreign keys. So I defined two entities as follow public class Employee { public int EmployeeId { get; set; } public string Name { get; set; } [ForeignKey(\"FirstTeam\")] public int FirstTeamId { get; set; } [InverseProperty(\"FirstEmployees\")] public virtual Team FirstTeam { get; set; } [ForeignKey(\"SecondTeam\")] public int SecondTeamId { get; set; } [InverseProperty(\"SecondEmployees\")] public virtual Team SecondTeam {

How to add “on delete cascade” constraints?

瘦欲@ 提交于 2019-11-26 07:59:40
问题 In PostgreSQL 8 is it possible to add ON DELETE CASCADES to the both foreign keys in the following table without dropping the latter? # \\d scores Table \"public.scores\" Column | Type | Modifiers ---------+-----------------------+----------- id | character varying(32) | gid | integer | money | integer | not null quit | boolean | last_ip | inet | Foreign-key constraints: \"scores_gid_fkey\" FOREIGN KEY (gid) REFERENCES games(gid) \"scores_id_fkey\" FOREIGN KEY (id) REFERENCES users(id) Both

JPA/Hibernate remove entity sometimes not working

核能气质少年 提交于 2019-11-26 07:27:32
问题 I have the following code that usually works well: public void delete(T object) { EntityManager em = getPersistence().createEntityManager(); EntityTransaction et = em.getTransaction(); try { et.begin(); object = em.find(object.getClass(), object.getId()); em.remove(object); em.flush(); et.commit(); } catch(Exception e) { error(\"Unable to delete \" + object.toString() + \": there are references to it.\"); } finally { if (et.isActive()) et.rollback(); em.close(); } } For many of my entity

Is it possible to delete from multiple tables in the same SQL statement?

微笑、不失礼 提交于 2019-11-26 06:44:53
问题 It\'s possible to delete using join statements to qualify the set to be deleted, such as the following: DELETE J FROM Users U inner join LinkingTable J on U.id = J.U_id inner join Groups G on J.G_id = G.id WHERE G.Name = \'Whatever\' and U.Name not in (\'Exclude list\') However I\'m interested in deleting both sides of the join criteria -- both the LinkingTable record and the User record on which it depends. I can\'t turn cascades on because my solution is Entity Framework code first and the