@@ -191,6 +191,8 @@ def __add__(self, arg):
191191 new = nx .algorithms .boundary .node_boundary (self , self .nodes_to_show )
192192 if not new :
193193 break
194+ # add nodes referenced by aliased nodes
195+ new .update (nx .algorithms .boundary .node_boundary (self , (a for a in new if a .isdigit ())))
194196 self .nodes_to_show .update (new )
195197 return self
196198
@@ -207,9 +209,12 @@ def __sub__(self, arg):
207209 self .nodes_to_show .remove (arg .full_table_name )
208210 except AttributeError :
209211 for i in range (arg ):
210- new = nx .algorithms .boundary .node_boundary (nx .DiGraph (self ).reverse (), self .nodes_to_show )
212+ graph = nx .DiGraph (self ).reverse ()
213+ new = nx .algorithms .boundary .node_boundary (graph , self .nodes_to_show )
211214 if not new :
212215 break
216+ # add nodes referenced by aliased nodes
217+ new .update (nx .algorithms .boundary .node_boundary (graph , (a for a in new if a .isdigit ())))
213218 self .nodes_to_show .update (new )
214219 return self
215220
@@ -229,8 +234,10 @@ def _make_graph(self):
229234 """
230235 # mark "distinguished" tables, i.e. those that introduce new primary key attributes
231236 for name in self .nodes_to_show :
232- foreign_attributes = set (attr for p in self .in_edges (name , data = True ) for attr in p [2 ]['attr_map' ])
233- self .node [name ]['distinguished' ] = foreign_attributes < self .node [name ]['primary_key' ]
237+ foreign_attributes = set (
238+ attr for p in self .in_edges (name , data = True ) for attr in p [2 ]['attr_map' ] if p [2 ]['primary' ])
239+ self .node [name ]['distinguished' ] = (
240+ 'primary_key' in self .node [name ] and foreign_attributes < self .node [name ]['primary_key' ])
234241 # include aliased nodes that are sandwiched between two displayed nodes
235242 gaps = set (nx .algorithms .boundary .node_boundary (self , self .nodes_to_show )).intersection (
236243 nx .algorithms .boundary .node_boundary (nx .DiGraph (self ).reverse (), self .nodes_to_show ))
0 commit comments