Skip to content

Improve documentation for hydrating collections based on queries returning paths. #2210

Closed
@BenBohannon

Description

@BenBohannon

On 6.0.7, I'm trying to use a custom query like this:

MATCH p = (leaf:PERSON {number: $a})-[:SOME_RELATION_TO*]-(:PERSON) 
RETURN leaf, collect(nodes(p)), collect(relationships(p))

to get all paths from a single PERSON node to all other PERSON nodes connected by SOME_RELATION_TO regardless of direction or depth, and I also need the relationship properties between each node.

Entities:

@Node("PERSON")
public class Person {
    @Id
    private final Long number;

    @Property("name")
    private String name;

    @Relationship(type = "SOME_RELATION_TO", direction = OUTGOING)
    private Set<SomeRelation> someRelationsOut = new HashSet<>();
}
@RelationshipProperties
public class SomeRelation {
    @Id @GeneratedValue private Long id;

    @Property private double someData;

    @TargetNode private Person targetPerson;
}
@Query("MATCH p = (leaf:PERSON {number: $a})-[:SOME_RELATION_TO*]-(:PERSON) RETURN leaf, collect(nodes(p)), collect(relationships(p))")
List<Person> getRelated(Long a);

My problem is that performing this query from a leaf node (only incoming directions) yields a list containing only the leaf node without any other relationships (since it technically has none outgoing?). The query only returns other nodes/relationships when performed from a node with outgoing directions.

My graph is acylic and only composed of a single node and relation type.
E.g. Person A -> Person B <- Person C <- Person D
If the query is performed from Person A, then I only get Persons A and B. If performed from Person B, then I only get Person B.

Should my query be different? Or is this a limitation of the object mapping or bi-directional relationships?

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions