Skip to content

Commit f41d474

Browse files
Merge pull request #557 from kimehta/master
Highlight "distinguished" classes in the ERD #378
2 parents 5c4b5c1 + 40280ad commit f41d474

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

datajoint/erd.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ def __init__(self, source, context=None):
121121
if node.startswith('`%s`' % database):
122122
self.nodes_to_show.add(node)
123123

124+
for full_table_name in self.nodes_to_show:
125+
#one entry per parent
126+
parents = connection.dependencies.parents(full_table_name,True)
127+
128+
# all the foreign primary keys
129+
# set because multiple foreign constraints can be applied on the same local attribute
130+
foreign_primary_attributes = set(attr for parent in parents.values() for attr in parent['attr_map'].keys())
131+
132+
#distinguished table if table introduces atleast one primary key in the schema
133+
self.nodes._nodes[full_table_name]['distinguished'] = foreign_primary_attributes < self.nodes._nodes[full_table_name]['primary_key']
134+
124135
@classmethod
125136
def from_sequence(cls, sequence):
126137
"""
@@ -260,7 +271,7 @@ def make_dot(self):
260271
'-'*30 if q.startswith('---') else q.replace('->', '&#8594;') if '->' in q else q.split(':')[0]
261272
for q in description if not q.startswith('#'))
262273
node.set_tooltip('&#13;'.join(description))
263-
node.set_label(name)
274+
node.set_label("<<u>"+name+"</u>>" if node.get('distinguished') == 'True' else name)
264275
node.set_color(props['color'])
265276
node.set_style('filled')
266277

0 commit comments

Comments
 (0)