Permalink
Browse files

bug fix: np check, check for generic relationships

  • Loading branch information...
1 parent a95c691 commit 389fe4af4e0b80860c8f92973d2e9072c22705e1 @amorgner amorgner committed May 15, 2012
Showing with 34 additions and 27 deletions.
  1. +34 −27 structr/structr-core/src/main/java/org/structr/core/entity/RelationClass.java
@@ -146,47 +146,54 @@ public Object execute() throws FrameworkException {
newRel.setProperty(AbstractRelationship.HiddenKey.cascadeDelete, cascadeDelete);
}
- }
+ switch (cardinality) {
- switch (cardinality) {
+ case ManyToOne :
+ case OneToOne : {
- case ManyToOne :
- case OneToOne : {
+ Class destType = finalTargetNode.getClass();
- Class destType = finalTargetNode.getClass();
+ // delete previous relationships to nodes of the same destination type and direction
+ List<AbstractRelationship> rels = finalSourceNode.getRelationships(relType, direction);
- // delete previous relationships to nodes of the same destination type and direction
- List<AbstractRelationship> rels = finalSourceNode.getRelationships(relType, direction);
+ for (AbstractRelationship rel : rels) {
- for (AbstractRelationship rel : rels) {
-
- // if (rel.getOtherNode(finalSourceNode).getType().equals(destType)) {
- // if (destType.isAssignableFrom(rel.getOtherNode(finalSourceNode).getClass())) {
- if (!rel.equals(newRel) && newRel.getClass().isAssignableFrom(rel.getClass())) {
-
- deleteRel.execute(rel);
+ // if (rel.getOtherNode(finalSourceNode).getType().equals(destType)) {
+ // if (destType.isAssignableFrom(rel.getOtherNode(finalSourceNode).getClass())) {
+
+ if ((!rel.equals(newRel)
+ && ((!(rel instanceof GenericRelationship) && newRel.getClass().isAssignableFrom(rel.getClass()))
+ || destType.isAssignableFrom(rel.getOtherNode(finalSourceNode).getClass())))) {
+
+ deleteRel.execute(rel);
+ }
}
- }
- break;
+ break;
- }
-
- case OneToMany : {
+ }
- // Here, we have a OneToMany with OUTGOING Rel, so we need to remove all relationships
- // of the same type incoming to the target node
- List<AbstractRelationship> rels = finalTargetNode.getRelationships(relType, Direction.INCOMING);
+ case OneToMany : {
- for (AbstractRelationship rel : rels) {
+ Class sourceType = finalSourceNode.getClass();
+
+ // Here, we have a OneToMany with OUTGOING Rel, so we need to remove all relationships
+ // of the same type incoming to the target node
+ List<AbstractRelationship> rels = finalTargetNode.getRelationships(relType, Direction.INCOMING);
- // if (rel.getOtherNode(finalTargetNode).getType().equals(sourceNode.getType())) {
- // if (sourceNode.getClass().isAssignableFrom(rel.getOtherNode(finalTargetNode).getClass())) {
- if (!rel.equals(newRel) && newRel.getClass().isAssignableFrom(rel.getClass())) {
+ for (AbstractRelationship rel : rels) {
- deleteRel.execute(rel);
+ // if (rel.getOtherNode(finalTargetNode).getType().equals(sourceNode.getType())) {
+ // if (sourceNode.getClass().isAssignableFrom(rel.getOtherNode(finalTargetNode).getClass())) {
+ if ((!rel.equals(newRel)
+ && ((!(rel instanceof GenericRelationship) && newRel.getClass().isAssignableFrom(rel.getClass()))
+ || sourceType.isAssignableFrom(rel.getOtherNode(finalTargetNode).getClass())))) {
+
+ deleteRel.execute(rel);
+ }
}
}
+
}
}

0 comments on commit 389fe4a

Please sign in to comment.