如何在neo4django中扩展Relationship类 [英] How to extend Relationship class in neo4django

查看:156
本文介绍了如何在neo4django中扩展Relationship类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到neo4django中尚未实现关系属性. 此线程中公开的解决方法是为每个与属性的关系都使用新的节点类型. >

我负担不起太多的计算,所以我不想使用这种技术.在阅读源代码时,我已经视为Relationship类的文档字符串,它是:"""Extend to add properties to relationships."""

我的问题是,该怎么做?从哪里开始添加至少一个属性?

谢谢

解决方案

尽管有文档字符串,但这仍然是

WDYT?

I've seen that relationship properties are not yet implemented in neo4django. The workaround exposed in this thread is to have a new node type for each relationship with a property.

I can't afford too much calculations so I don't want to use this technique. While reading the source code I've seen, as the docstring of the Relationship class, this : """Extend to add properties to relationships."""

My question is, how to do that ? Where to start to add at least one property ?

Thanks

解决方案

Despite the docstring, this is still an open issue- the project's oldest, actually. There might be a way for you to pull it off by extending Relationship and BoundRelationship, but it won't be easy until I'm able to close that issue.

I would argue that this issue probably won't be a bottleneck using the project, since you can just give Neo4j more memory for the node store than the relationship store to account for it. YMMV of course.

I know it feels like a hack, though. If you really need custom relationship properties, the shortest path might be dropping down to the REST client level. To create relationships with properties, you could do something like

class Person(NodeModel):
  name = StringProperty()
  friends = Relationship('self', rel_type='friends_with')

pete = Person.objects.create(name='Pete')
dave = Person.objects.create(name='Dave')

# from the neo4j-rest-client [docs][2]
pete.node.relationships.create("friends_with", dave.node, since=123456789, introduced_at="Christmas party")

WDYT?

这篇关于如何在neo4django中扩展Relationship类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆