模型是这样的(在 SQLAlchemy 中):
Class Cell(Base):
__tablename__ = "cell"
id = Column(Integer)
name = Column(String)
Class Sample(Base):
__tablename__ = "cell"
id = Column(Integer)
factor_id = Column(Integer, ForeignKey("cell.id"))
cell = relationship(Cell, backref = 'sample', order_by = "Cell.id")
当我执行这样的查询时:
DBSession.query(Sample).filter(Sample.cell.name == "a_string")
它会抛出这样的异常:
File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/attributes.py", line 139, in __getattr__
key)
AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' object has an attribute 'name'
似乎类中的cell
字段Sample
没有名为name
. 那么如何Cell.name
在Sample
课堂上查询cell
字段呢?有人对此有想法吗?
谢谢!