FreeTAKTeam / DigitalPy

A framework to support digital engineering in the python language
Eclipse Public License 2.0
8 stars 4 forks source link

59 add support model relationships #60

Closed naman108 closed 5 months ago

naman108 commented 5 months ago

Description

This pull request defines a new decorator for nodes to define relationships similarly to how the property decorator is implemented.

Functionality

This decorator can be used as follows:

from digitalpy.core.domain.relationship import Relationship, RelationshipType
from digitalpy.core.domain.node import Node

class Parent(Node):

    @Relationship(reltype=RelationshipType.ASSOCIATION, multiplicity_lower=2, multiplicity_upper=5)
    def children(self):
        return self._children

    @names.setter
    def children(self, value):
        self._children = value

This will restrict any more than five children or any less than two children from being added.

Navigability can be used as follows:

from digitalpy.core.domain.relationship import Relationship, RelationshipType
from digitalpy.core.domain.node import Node

class Parent(Node):

    @Relationship(reltype=RelationshipType.ASSOCIATION, navigable=False)
    def hidden(self):
        return self._hidden

    @hidden.setter
    def hidden(self, value):
        self._hidden = hidden

now the getter cannot be accessed so any operation such as print(parent_inst.hidden) would fail.