Skip to content
Robin Edwards edited this page Jan 30, 2014 · 21 revisions

(Used to be called traverse())

class Address(StructuredNode):
   name = StringProperty()
   street = StringProperty()
   town = StringProperty()
   post_code = StringProperty()

class Car(StructuredNode):
   model = StringProperty(unique_index=True)
   

class User(StructuredNode):
   name = StringProperty(unique_index=True)
   age = IntegerProperty()
   friend = Relationship(Address, 'FRIEND', ZeroOrMore)
   address = Relationship(Address, 'ADDRESS', ZeroOrOne)
   car =  Relationship(Address, 'CAR', ZeroOrOne)

Matching by label from a class

User.filter(age__lt=16)
User.exclude(age__lt=16)

# chain able:
User.filter(age__lt=16).exclude(age__lt=4)

Relationship manager methods

jim.friends.all()

# only where rel property since is less than year
jim.friends.match(since__lt=year())

# replaces search() as that is now deprecated
jim.friends.filter(age__gt=5)
jim.friends.exclude(age__lt=18) # negated

Match and filter

match rels with properties then filter on node properties

jim.friends.match(since__gt=yesterday()).filter(age__gt=5)

2 level match

jim.friends.match(since__lt=year()).car.match(**kwargs).filter(model="")

filtering nodes with or without a relationship

# users older than 18 who own a car made over 2 years ago but don't have an address
Users.filter(age__gt=18).has(
    car=Car.filter(manufactured__lt=two_years()),
    address=False)

Issues:

  • multi type relationships - disable chaining on multi type relationships.
  • how to return multiple types of node
Clone this wiki locally