@@ -190,14 +190,22 @@ Statement toStatement(NodeDescription<?> nodeDescription) {
190
190
Relationship relationships = Cypher .anyNode ().relationshipBetween (Cypher .anyNode ()).named (relationshipIds );
191
191
return Cypher .match (rootNodes )
192
192
.where (Functions .id (rootNodes ).in (Cypher .parameter (rootNodeIds )))
193
+ .with (Functions .collect (rootNodes ).as (Constants .NAME_OF_ROOT_NODE ))
193
194
.optionalMatch (relationships )
194
195
.where (Functions .id (relationships ).in (Cypher .parameter (relationshipIds )))
196
+ .with (Constants .NAME_OF_ROOT_NODE , Functions .collectDistinct (relationships ).as (Constants .NAME_OF_SYNTHESIZED_RELATIONS ).asExpression ())
195
197
.optionalMatch (relatedNodes )
196
198
.where (Functions .id (relatedNodes ).in (Cypher .parameter (relatedNodeIds )))
197
199
.with (
198
- rootNodes .as (Constants .NAME_OF_TYPED_ROOT_NODE .apply (nodeDescription ).getValue ()),
199
- Functions .collectDistinct (relationships ).as (Constants .NAME_OF_SYNTHESIZED_RELATIONS ),
200
- Functions .collectDistinct (relatedNodes ).as (Constants .NAME_OF_SYNTHESIZED_RELATED_NODES ))
200
+ Constants .NAME_OF_ROOT_NODE ,
201
+ Cypher .name (Constants .NAME_OF_SYNTHESIZED_RELATIONS ).as (Constants .NAME_OF_SYNTHESIZED_RELATIONS ),
202
+ Functions .collectDistinct (relatedNodes ).as (Constants .NAME_OF_SYNTHESIZED_RELATED_NODES ).asExpression ()
203
+ )
204
+ .unwind (Constants .NAME_OF_ROOT_NODE ).as (rootNodeIds )
205
+ .with (
206
+ Cypher .name (rootNodeIds ).as (Constants .NAME_OF_TYPED_ROOT_NODE .apply (nodeDescription ).getValue ()).asExpression (),
207
+ Cypher .name (Constants .NAME_OF_SYNTHESIZED_RELATIONS ),
208
+ Cypher .name (Constants .NAME_OF_SYNTHESIZED_RELATED_NODES ))
201
209
.orderBy (queryFragments .getOrderBy ())
202
210
.returning (
203
211
Constants .NAME_OF_TYPED_ROOT_NODE .apply (nodeDescription ).as (Constants .NAME_OF_SYNTHESIZED_ROOT_NODE ),
0 commit comments