J'ai deux noeuds A
et B
. Ils ont une relation dirigée de A
à B
. Par conséquent, A
a un ConnectedTo
attribué au type RelatedTo
. Cependant, je veux parcourir tous les noeuds B
et accéder aux relations entrantes de A
.ObjectModel accédant aux relations entrantes
Comment est-ce que je peux faire ceci?
J'ai essayé d'ajouter un attribut de type ConnectedTo
RelatedFrom
-B
mais lorsque vous interrogez le graphique que je reçois un ValueError('Invalid Identifier')
.
class A(GraphObject):
__primarykey__ = "hash"
hash = Property()
ConnectedTo = RelatedTo('B')
def __init__(self, hash):
self.hash = hash
class B(GraphObject):
__primarykey__ = "hash"
hash = Property()
ConnectedTo = RelatedFrom('A')
def __init__(self, hash):
self.hash = hash
>>> a = A("testA")
>>> b = B("testB")
>>> a.ConnectedTo.add(b)
>>> graph.push(a)
>>> graph.push(b)
>>> test = B.select(graph).first()
Résultats en erreur:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/py2neo/ogm.py", line 442, in first
return self._object_class.wrap(super(GraphObjectSelection, self).first())
File "/usr/local/lib/python2.7/dist-packages/py2neo/ogm.py", line 344, in wrap
_ = getattr(inst, attr)
File "/usr/local/lib/python2.7/dist-packages/py2neo/ogm.py", line 90, in __get__
related[key] = RelatedObjects(cog.node, self.direction, self.relationship_type, self.related_class)
File "/usr/local/lib/python2.7/dist-packages/py2neo/ogm.py", line 135, in __init__
self.__relationship_pattern = "(a)<-[_:%s]-(b)" % cypher_escape(relationship_type)
File "/usr/local/lib/python2.7/dist-packages/py2neo/database/cypher.py", line 221, in cypher_escape
writer.write_identifier(identifier)
File "/usr/local/lib/python2.7/dist-packages/py2neo/database/cypher.py", line 78, in write_identifier
raise ValueError("Invalid identifier")
ValueError: Invalid identifier