Delete recursive: true with a ManyToMany relationship doesn't delete intermediate records

Issue #21 new
Dustin Friel created an issue

I have a Students and Incidents defined like

public class Incident {
    [PrimaryKey]
    [AutoIncrement]
    public int Id { get; set; }

    [ManyToMany(typeof(StudentIncident))]
    public List<Student> Students { get; set; }

}

public class Student {
    [PrimaryKey]
    [AutoIncrement]
    public int Id { get; set; }

    [ManyToMany(typeof(StudentIncident))]
    public List<Incident> Incidents { get; set; }

}

public class StudentIncident
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }

    [ForeignKey(typeof(Student))]
    public int StudentId { get; set; }

    [ForeignKey(typeof(Incident))]
    public int IncidentId { get; set; }

}

When I call InsertWithChildren (item, recursive: true); of an Incident with Students all the data is inserted into the three tables correctly correctly.

When I call Delete (item, recursive: true); of an Incident or Student the applicable row in the intermediate table (StudentIncident) isn't removed. Note I don't want to the associated Incidents or Students deleted. But I was expecting the associated rows in the intermediate table to be removed.

Is that table something that needs to be handled manually on Delete? A mistake in how I'm defining the ManyToMany? Or a defect?

Comments (3)

  1. Guillermo GutiƩrrez

    Yes, it's a known issue. It's harmless because the ID won't be used by a new entity and they intermediate elements will be deleted as soon as the relationship is updated, but it's something I could take a look in depth.

  2. Log in to comment