Skip to content

Enable multiple relation labels (a)-[r:TYPE1|TYPE2]->(b) in builder #533

@AntonLydike

Description

@AntonLydike

As per documentation you can supply the explicit relationship traversal settings with relation_type of None|*|<name>:

definition = dict(node_class=Person, direction=OUTGOING,
                 relation_type=None, model=None)
relations_traversal = Traversal(jim, Person.__label__,
                               definition)
all_jims_relations = relations_traversal.all()

The defintion argument is a mapping with these items:

node_class The class of the traversal target node.
direction match.OUTGOING / match.INCOMING / match.EITHER
relation_type Can be None (for any direction), * for all paths or an explicit name of a relation type (the edge’s label).
model The class of the relation model, None for such without one.

My suggestion is to extends this to include a list of names. This would result in a query using the (a)-[:TYPE1|TYPE2]->(b) syntax described by the neo4j docs here. This neo4j feature is supported since at least version 3.5, so compatibility should be of no concern.

This would be an example usage:

definition = dict(node_class=Person, direction=INCOMING,
                  relation_type=('FATHER','MOTHER'), model=None)
relations_traversal = Traversal(jim, Person.__label__,
                                definition)
all_jims_children = relations_traversal.all()

I am currently working on a PR, feedback is appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureDescribes a new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions