Skip to content

Proposal for modelling relationships with Nodes #73

@barbogast

Description

@barbogast

I'm developing an application with specific types of Nodes. I'm able to model the nodes using the Node class, but I cannot model which node type may have a relationship with which node type.

I was thinking of defining the relationships along with the properties:

class Category(Node):
    element_type = 'category'
    label = String(nullable=False)

class Tag(Node):
    element_type = 'tag'
    label = String(nullable=False)

class Issue(Node):
    element_type = 'issue'
    text = String(nullable=False)
    category = Relationship('has_category', Category, multi=False, nullable=False)
    tags = Relationship('has_tag', Tag, multi=True)


>>> category1 = Category(label='Proposal')
>>> tag1 = Tag(label='Proposal')
>>> tag2 = Tag(label='Question')

>>> issue1 = Issue(text='Modelling relationships would be nice', 
...                    category=category1,
...                    tags=[tag1, tag2])

>>> # it could also be possible to append multi-relationships afterwards
>>> tag3 = Tag(label='xxx')
>>> issue1.tags.append(tag3)

>>> # an Exception would be raised if a relationship is missing which is not nullable
>>> issue2 = Issue(text='Category is missing here')
ValueError('This Node must have a least one relation to <Category>')

I need to control the relationships between the nodes so I need to implement something like this. If you like the idea I could try to get it into bulbs, so you could merge it. If you dont think that it fits into bulbs, I would write it on top of bulbs I dont have to maintain a fork of bulbs.

Details:

  • It should be possible to have to different relationship types between the same node types.
  • How can 2 Nodes have relationships to each other? The class of the second node wont be available when the first one ist created. One solution could be to add the relationship of the first node after the second node is created.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions