@@ -181,7 +181,6 @@ boolean hasRootNodeIds() {
181
181
}
182
182
183
183
Statement toStatement () {
184
-
185
184
String rootNodeIds = "rootNodeIds" ;
186
185
String relationshipIds = "relationshipIds" ;
187
186
String relatedNodeIds = "relatedNodeIds" ;
@@ -190,14 +189,20 @@ Statement toStatement() {
190
189
Relationship relationships = Cypher .anyNode ().relationshipBetween (Cypher .anyNode ()).named (relationshipIds );
191
190
return Cypher .match (rootNodes )
192
191
.where (Functions .id (rootNodes ).in (Cypher .parameter (rootNodeIds )))
192
+ .with (Functions .collect (rootNodes ).as ("n" ))
193
193
.optionalMatch (relationships )
194
194
.where (Functions .id (relationships ).in (Cypher .parameter (relationshipIds )))
195
+ .with (Constants .NAME_OF_ROOT_NODE , Functions .collectDistinct (relationships ).as (Constants .NAME_OF_SYNTHESIZED_RELATIONS ).asExpression ())
195
196
.optionalMatch (relatedNodes )
196
197
.where (Functions .id (relatedNodes ).in (Cypher .parameter (relatedNodeIds )))
197
- .with (
198
- rootNodes .as (Constants .NAME_OF_ROOT_NODE .getValue ()),
199
- Functions .collectDistinct (relationships ).as (Constants .NAME_OF_SYNTHESIZED_RELATIONS ),
200
- Functions .collectDistinct (relatedNodes ).as (Constants .NAME_OF_SYNTHESIZED_RELATED_NODES ))
198
+ .with (Constants .NAME_OF_ROOT_NODE ,
199
+ Cypher .name (Constants .NAME_OF_SYNTHESIZED_RELATIONS ).as (Constants .NAME_OF_SYNTHESIZED_RELATIONS ),
200
+ Functions .collectDistinct (relatedNodes ).as (Constants .NAME_OF_SYNTHESIZED_RELATED_NODES ).asExpression ()
201
+ )
202
+ .unwind (Constants .NAME_OF_ROOT_NODE ).as (rootNodeIds )
203
+ .with (Cypher .name (rootNodeIds ).as (Constants .NAME_OF_ROOT_NODE ).asExpression (),
204
+ Cypher .name (Constants .NAME_OF_SYNTHESIZED_RELATIONS ),
205
+ Cypher .name (Constants .NAME_OF_SYNTHESIZED_RELATED_NODES ))
201
206
.orderBy (queryFragments .getOrderBy ())
202
207
.returning (
203
208
Constants .NAME_OF_ROOT_NODE .as (Constants .NAME_OF_SYNTHESIZED_ROOT_NODE ),
0 commit comments