How to extend Relationship class in neo4django

99封情书 提交于 2019-12-11 03:55:14

问题


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


回答1:


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?



来源:https://stackoverflow.com/questions/16218181/how-to-extend-relationship-class-in-neo4django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!