Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python SQLAlchemy-经典映射关系_Python_Python 2.7_Python 3.x_Sqlalchemy - Fatal编程技术网

Python SQLAlchemy-经典映射关系

Python SQLAlchemy-经典映射关系,python,python-2.7,python-3.x,sqlalchemy,Python,Python 2.7,Python 3.x,Sqlalchemy,我在SQLAlchemy经典映射方面有点困难。我的情况如下: class Manager(object): def __init__(self): self.id = uuid.uuid4() ..... class Client(object): def __init__(self): self.id = uuid.uuid4() self.manager = None 我想做的是说服SQLAlchemy在客户机和

我在SQLAlchemy经典映射方面有点困难。我的情况如下:

class Manager(object):
    def __init__(self):
       self.id = uuid.uuid4()
       .....

class Client(object):
    def __init__(self):
        self.id = uuid.uuid4()
        self.manager = None
我想做的是说服SQLAlchemy在客户机和经理(客户机有经理)之间创建关系,而不必在客户机级别定义经理id属性。在上面的代码中,“manager”属性将是manager类的一个实例。在这种情况下,我使用的是经典映射。任何帮助都将不胜感激

mapper(Client, self._table, column_prefix='_', properties={'managed_by_relation':relationship(User, order_by=self._table.c.id, foreign_keys=[self._table.c.manager_id]))

上面的代码描述了我试图避免的内容。

似乎您正在寻找某种方法来自动创建ForeignKey?我在这里写了一篇博客文章,介绍了一种模拟更“传统”的声明式ORM的可能方法:

谢谢Mike,非常感谢。我今天要看一看。希望我能带着更多的问题回来,你不会介意:)。