Author: michiel
Date: 2009-06-05 09:06:34 +0200 (Fri, 05 Jun 2009)
New Revision: 35740

Modified:
   mmbase/trunk/core/src/main/java/org/mmbase/bridge/util/Queries.java
Log:
  MMB-1827

Modified: mmbase/trunk/core/src/main/java/org/mmbase/bridge/util/Queries.java
===================================================================
--- mmbase/trunk/core/src/main/java/org/mmbase/bridge/util/Queries.java 
2009-06-05 02:01:24 UTC (rev 35739)
+++ mmbase/trunk/core/src/main/java/org/mmbase/bridge/util/Queries.java 
2009-06-05 07:06:34 UTC (rev 35740)
@@ -1032,7 +1032,14 @@
      */
     public static NodeQuery createRelatedNodesQuery(Node node, NodeManager 
otherNodeManager, String role, String direction) {
         NodeQuery query = createNodeQuery(node);
-        if (otherNodeManager == null) otherNodeManager = 
node.getCloud().getNodeManager("object");
+        if (node.isNew()) {
+            // new nodes do not have related nodes, make sure the query 
returns nothing either
+            addConstraint(query, createMakeEmptyConstraint(query));
+        }
+        if (otherNodeManager == null) {
+            otherNodeManager = node.getCloud().getNodeManager("object");
+        }
+
         RelationStep step = query.addRelationStep(otherNodeManager, role, 
direction);
         query.setNodeStep(step.getNext());
         return query;
@@ -1048,7 +1055,13 @@
      */
     public static NodeQuery createRelationNodesQuery(Node node, NodeManager 
otherNodeManager, String role, String direction) {
         NodeQuery query = createNodeQuery(node);
-        if (otherNodeManager == null) otherNodeManager = 
node.getCloud().getNodeManager("object");
+        if (node.isNew()) {
+            // new nodes do not have related nodes
+            addConstraint(query, createMakeEmptyConstraint(query));
+        }
+        if (otherNodeManager == null) {
+            otherNodeManager = node.getCloud().getNodeManager("object");
+        }
         RelationStep step = query.addRelationStep(otherNodeManager, role, 
direction);
         query.setNodeStep(step);
         return query;
@@ -1072,6 +1085,10 @@
      */
     public static NodeQuery createRelationNodesQuery(Node node, Node 
otherNode, String role, String direction) {
         NodeQuery query = createNodeQuery(node);
+        if (node.isNew()) {
+            // new nodes do not have related nodes
+            addConstraint(query, createMakeEmptyConstraint(query));
+        }
         NodeManager otherNodeManager = otherNode.getNodeManager();
         RelationStep step = query.addRelationStep(otherNodeManager, role, 
direction);
         Step nextStep = step.getNext();

_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to