public void delete() {
for (EORelationship relation : entity().relationships()) {
// to-many relationship that is not in class properties with
// cascade as delete rule
if (relation.isToMany()
&& relation._stringFromDeleteRule(relation.deleteRule())
.equals(EORelationship.DeleteRuleCascadeString)
&& !entity().classPropertyNames().contains(relation.name())) {
EOQualifier qualifier = relation.qualifierWithSourceRow(this
.snapshot());
EOFetchSpecification fetchSpecification = new EOFetchSpecification(
relation.destinationEntity().name(), qualifier, null);
// fetching objects for the relationship
NSArray<ERXGenericRecord> objects = editingContext()
.objectsWithFetchSpecification(fetchSpecification);
// now delete them
for (ERXGenericRecord eoGenericRecord : objects) {
eoGenericRecord.delete();
}
}
}
super.delete();
}