我有 2 个结构化节点User
,并且Token
是一对一的关系。来自将 Django 用于关系数据库,如果我想给用户一个令牌,我会简单地做User.objects.get(token__key=token)
.
但是将 Neo4j 与 NeoModel 一起使用,我正在努力寻找一种方法来执行这个简单的查询。我必须为此使用密码吗?如果是这样怎么办?
此外,当我拥有User
实例时,我可以user.token.single()
获取Token
实例,但反过来也行不通。token.user.single()
返回CardinalityViolation: Expected: one relationship in a outgoing direction of type FOR_USER on node (49) of class 'Token', got: none.
并且 token.user 返回一个neomodel.cardinality.One
对象。
class User(DjangoNode):
uid = UniqueIdProperty()
firstname = StringProperty(index=True, required=True)
lastname = StringProperty(index=True, required=True)
email = EmailProperty(unique_index=True, required=True)
password = StringProperty(requried=True)
token = RelationshipFrom('Token', 'OWNS_TOKEN', cardinality=One)
def post_create(self):
token = Token().save()
self.token.connect(token)
class Token(DjangoNode):
user = RelationshipTo('Token', 'FOR_USER', cardinality=One)
key = StringProperty(unique_index=True, default=generate_key)
created = DateTimeProperty(default_now=True)