Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.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 SQL炼金术查询与急切加载的关系?_Python_Sqlalchemy - Fatal编程技术网

Python SQL炼金术查询与急切加载的关系?

Python SQL炼金术查询与急切加载的关系?,python,sqlalchemy,Python,Sqlalchemy,在查询中使用SA的急切关系加载时遇到问题 我有两个表是这样声明的: class Score(Base): __tablename__ = 'Score' school = relationship("School", backref='score') SchoolKey = Column('SchoolKey', Integer, primary_key=True) class School(Base): __tablename__ = 'School'

在查询中使用SA的急切关系加载时遇到问题

我有两个表是这样声明的:

class Score(Base):
    __tablename__ = 'Score'

    school = relationship("School", backref='score')
    SchoolKey = Column('SchoolKey', Integer, primary_key=True)


class School(Base):
    __tablename__ = 'School'

    SchoolKey = deferred(Column('SchoolKey', Integer, primary_key=True))
    SchoolName = Column('SchoolName', String)
    SchoolDistrict = deferred(Column('SchoolDistrict', String), group = 'district')
    SchoolDistrictID = deferred(Column('SchoolDistrictID', integer), group = 'district')
我想用来自学校表的筛选条件尽可能简洁地查询我的分数表。因此,我热切期待着这段关系

现在,当我查询时,我无法使其工作:

session.query(Score).filter(School.SchoolName == 'RandomName')
(这实际上只是让我的电脑崩溃)有人知道如何让它工作吗?

上下文:我知道对于我的示例来说这听起来很琐碎,但是Score是一个事实表,位于>10个表的中心。我真的不想写10。将部分连接到任何要筛选的查询。所以我想避免这样的事情:

session.query(Score).join(School).filter(School.SchoolName == 'RandomName')
session.query(Score).join(School).filter(School.SchoolName == 'RandomName')

临时解决方案:只是接受我需要为所有维度表编写联接: