Problems Migrating from Binding Relationships to a list in a Variable Length Pattern to Non Deprecated Format

So I have the following cypher example that I use to help traverse a specific tree structure:

MATCH (start: node_label{id:1}) - [r:relationship_A|relationship_B*] -> (endNodes:node_label)
return size(r)/2, endNodes.id

Now this finds exactly what I need it to find: Traverse down recursively from a starting position and return me all nodes of the specified label that are connected through other nodes via relationship_A or relationship_B (the pattern I'm needing it to follow is start - [:relationship_A] -> () - [relationship_B] -> endNodes). Then return me the length of relationships divided by 2 (accounts for a single pattern traversal) along with the end node that was found.

Unfortunately it looks like this format of binding a variable length pattern with relationships to a list is going to be deprecated according to the following message:

Binding relationships to a list in a variable length pattern is deprecated. (Binding a variable length relationship pattern to a variable ('r') is deprecated and will be unsupported in a future version. The recommended way is to bind the whole path to a variable, then extract the relationships: MATCH p = (...)-[...]-(...) WITH *, relationships(p) AS r)

While I vaguely understand what the message is trying to tell me, having a difficult time matching this same cypher with the new pattern.

Closest I come is:

MATCH (start: node_label{id:1})-[*1..12]-> (endNodes:node_label)
MATCH p = (start)-[:relationship_A]->()-[:relationship_B]->(endNodes)
RETURN *, relationships(p) AS r

With this I am no getting no results back. Any help would be appreciated.

Does this work for you?

MATCH p = (start: node_label{id:1}) - [:relationship_A|relationship_B*] -> (endNodes:node_label)
RETURN size(relationships(p))/2, endNodes.id
1 Like

Perfect! Thank you so much for the help!

See what I was missing now with proper way to handle getting the relationships.