I'm creating a simple social graph where a user can create a post, tag it, and comment on it. I'm using py2neo to do the modelling. The model has user
and post
as nodes. A user TAGGED
, POSTED
, or COMMENTED
on a post
. In my case, a single user can create multiple tag
s or comment
s on a single post
(just like any social network out there). Based on my model, this necessitates multiple TAGGED
or COMMENTED
relationships but with distinct properties. The model is built thusly:
from py2neo.ogm import (
GraphObject,
Property,
RelatedTo,
RelatedFrom
)
class User(GraphObject):
__primarykey__ = 'name'
name = Property()
posts = RelatedTo('Post', 'POSTED')
comments = RelatedTo('Post', 'COMMENTED')
tags = RelatedTo('Post', 'TAGGED')
def __init__(self, name):
self.name = name
class Post(GraphObject):
# assumes __id__ as primary key because
# left undefined
title = Property()
users = RelatedFrom('User', 'POSTED')
comments = RelatedFrom('User', 'COMMENTED')
tags = RelatedFrom('User', 'TAGGED')
def __init__(self, title):
self.title = title
I run the following to build the graph:
user = User(name='john')
post = Post(title='Wow!')
user.posts.add(
post,
{'date': '2017-04-26'}
)
graph.push(user)
user.comments.add(
post,
{'caption': 'I know!', 'date': '2017-04-26'}
)
graph.push(user)
for tag in ['yellow', 'green']:
user.tags.add(
post,
{'tag': tag, 'date': '2017-04-26'}
)
graph.push(user)
I would expect there to be two TAGGED
relationships, something like this:
But I see this is not the case:
My question then is twofold. (1) Can create a multiple relationships of the same type with different properties? (2) Is this the best model choice for the use case?