iPhone Core Data: Cascading delete across a many-to-one relationship

前端 未结 2 1195
遥遥无期
遥遥无期 2020-12-24 13:20

I have two classes A and B with a many-to-one relationship from A to B (multiple A objects may reference the same B). The question is, if the delete rule on the A side is C

2条回答
  •  离开以前
    2020-12-24 14:02

    Here's a Swift 4 version of Lukas' answer:

    public override func prepareForDeletion() {
        guard let department = department else { return }
    
        if department.employees.filter({ !$0.isDeleted }).isEmpty {
            managedObjectContext?.delete(department)
        }
    }
    

提交回复
热议问题