Hello all,
Before getting into this, I read the docs, and understand that the current capabilities surrounding the cardinality of relationships entails:
It is possible to (softly) enforce cardinality constraints on your relationships. Remember this needs to be declared on both sides of the relationship definition
I'm assuming that what is meant by "softly" is that this cardinality is only enforced on the connecting side of the relationship.
Take for example, my use case. I have a single node that has ZeroOrMore OUTGOING relationships, each to nodes that have One INCOMING relationship corresponding to that. Kinda looks like this:

Essentially, the One constraint should make this following case impossible:

Which it is, if I try to connect it from the StructuredNode that has the RelationshipDefinition constrained by One. But if I connect from the ZeroOrMore connected node, the other node's constraints aren't checked. Example code below:
class Test(StructuredNode):
a = StringProperty(unique_index=True)
other = RelationshipFrom('Test2', 'IS_UNDER', cardinality=One)
def __init__(self, a, *args, **kwargs):
kwargs['a'] = a
super().__init__(*args, **kwargs)
class Test2(StructuredNode):
b = StringProperty(unique_index=True)
other = RelationshipTo('Test', 'IS_UNDER', cardinality=ZeroOrMore)
def __init__(self, b, *args, **kwargs):
kwargs['b'] = b
super().__init__(*args, **kwargs)
install_all_labels()
testHub = Test2('a').save()
single1 = Test('b').save()
single2 = Test('c').save()
single3 = Test('d').save()
testHub2 = Test2('z').save()
testHub.other.connect(single1)
testHub.other.connect(single2)
testHub.other.connect(single3)
testHub2.other.connect(single1) # should fail, but doesn't
single1.other.connect(testHub2) # should fail, and does
Should the target of a relationship be able to establish connections? And either way, shouldn't both source and target be responsible for understanding the constraints of each side? This feels like a pretty common use case to me, so I'm curious to see if anyone else shares this concern.
Hello all,
Before getting into this, I read the docs, and understand that the current capabilities surrounding the
cardinalityof relationships entails:I'm assuming that what is meant by "softly" is that this cardinality is only enforced on the connecting side of the relationship.
Take for example, my use case. I have a single node that has
ZeroOrMoreOUTGOINGrelationships, each to nodes that haveOneINCOMINGrelationship corresponding to that. Kinda looks like this:Essentially, the

Oneconstraint should make this following case impossible:Which it is, if I try to connect it from the
StructuredNodethat has theRelationshipDefinitionconstrained byOne. But if I connect from theZeroOrMoreconnected node, the other node's constraints aren't checked. Example code below:Should the target of a relationship be able to establish connections? And either way, shouldn't both source and target be responsible for understanding the constraints of each side? This feels like a pretty common use case to me, so I'm curious to see if anyone else shares this concern.