properties.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:annotated-py-sqlalchemy 作者: hhstore 项目源码 文件源码
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]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号