2

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

Community
  • 1
  • 1

1 Answers1

3

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?

Matt Luongo
  • 14,371
  • 6
  • 53
  • 64
  • Thanks @Matt, is it possible to do that from inside the class ? Like `self.node.relationships.create(...)` – Abdelhamid Belarbi Apr 29 '13 at 04:30
  • 1
    Absolutely. You could also do this in a Manager. If you need more power or want some custom relationship filtering to go along with your properties, you could try something like https://gist.github.com/bramd/5460611#file-models-py-L72 . (NB - in that example he's using Cypher, and the `node` variable would be better named `instance` to mark it as a model instance, not a REST client node object) – Matt Luongo Apr 29 '13 at 06:00
  • 1
    If you share some domain details or a motivating example, I'd be happy to provide a more tailored gist :) – Matt Luongo Apr 29 '13 at 06:00