def _find_dependent(self):
"""searches through the primary join condition to determine which side
has the primary key and which has the foreign key - from this we return
the "foreign key" for this property which helps determine one-to-many/many-to-one."""
# set as a reference to allow assignment from inside a first-class function
dependent = [None]
def foo(binary):
if binary.operator != '=':
return
if isinstance(binary.left, schema.Column) and binary.left.primary_key:
if dependent[0] is binary.left.table:
raise "bidirectional dependency not supported...specify foreignkey"
dependent[0] = binary.right.table
self.foreignkey= binary.right
elif isinstance(binary.right, schema.Column) and binary.right.primary_key:
if dependent[0] is binary.right.table:
raise "bidirectional dependency not supported...specify foreignkey"
dependent[0] = binary.left.table
self.foreignkey = binary.left
visitor = BinaryVisitor(foo)
self.primaryjoin.accept_visitor(visitor)
if dependent[0] is None:
raise "cant determine primary foreign key in the join relationship....specify foreignkey=<column> or foreignkey=[<columns>]"
else:
self.foreigntable = dependent[0]
评论列表
文章目录