Skip to content

Commit 0712e60

Browse files
Add doc
1 parent 2a7cf7e commit 0712e60

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

doc/source/traversal.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,26 @@ With both `traverse_relations` and `fetch_relations`, you can force the use of a
7777

7878
Person.nodes.fetch_relations('city__country', Optional('country')).all()
7979

80+
Unique variables
81+
----------------
82+
83+
If you want to use the same variable name for traversed nodes when chaining traversals, you can use the `unique_variables` method::
84+
85+
# This does not guarantee that coffees__species will traverse the same nodes as coffees
86+
# So coffees__species can traverse the Coffee node "Gold 3000"
87+
nodeset = (
88+
Supplier.nodes.fetch_relations("coffees", "coffees__species")
89+
.filter(coffees__name="Nescafe")
90+
)
91+
92+
# This guarantees that coffees__species will traverse the same nodes as coffees
93+
# So when fetching species, it will only fetch those of the Coffee node "Nescafe"
94+
nodeset = (
95+
Supplier.nodes.fetch_relations("coffees", "coffees__species")
96+
.filter(coffees__name="Nescafe")
97+
.unique_variables("coffees")
98+
)
99+
80100
Resolve results
81101
---------------
82102

0 commit comments

Comments
 (0)