@@ -52,7 +52,8 @@ class EdgeDefinition(object) :
5252 """An edge definition for a graph"""
5353
5454 def __init__ (self , edgesCollection , fromCollections , toCollections ) :
55- self .edgesCollection = self .name = edgesCollection
55+ self .name = edgesCollection
56+ self .edgesCollection = edgesCollection
5657 self .fromCollections = fromCollections
5758 self .toCollections = toCollections
5859
@@ -85,11 +86,28 @@ def __init__(self, database, jsonInit) :
8586 self ._rev = jsonInit ["_rev" ]
8687 self ._id = jsonInit ["_id" ]
8788
89+ orfs = set (self ._orphanedCollections )
90+ for o in jsonInit ["orphanCollections" ] :
91+ if o not in orfs :
92+ self ._orphanedCollections .append (o )
93+ if self .connection .verbose :
94+ print ("Orphan collection %s is not in graph definition. Added it" % o )
95+
8896 self .definitions = {}
97+ edNames = set ()
98+ for ed in self ._edgeDefinitions :
99+ self .definitions [ed .edgesCollection ] = ed .edgesCollection
100+
101+ for ed in jsonInit ["edgeDefinitions" ] :
102+ if ed ["collection" ] not in self .definitions :
103+ self .definitions [ed ["collection" ]] = EdgeDefinition (ed ["collection" ], fromCollections = ed ["from" ], toCollections = ed ["to" ])
104+ if self .connection .verbose :
105+ print ("Edge definition %s is not in graph definition. Added it" % ed )
106+
89107 for de in self ._edgeDefinitions :
90- if de .name not in self .database .collections and not COL .isEdgeCollection (de .name ) :
91- raise KeyError ("'%s' is not a valid edge collection" % de .name )
92- self .definitions [de .name ] = de
108+ if de .edgesCollection not in self .database .collections and not COL .isEdgeCollection (de .edgesCollection ) :
109+ raise KeyError ("'%s' is not a valid edge collection" % de .edgesCollection )
110+ self .definitions [de .edgesCollection ] = de
93111
94112 self .URL = "%s/%s" % (self .database .graphsURL , self ._key )
95113
0 commit comments