Python sqlalchemy:“InstrumentedList”对象没有属性“filter”

Python sqlalchemy:“InstrumentedList”对象没有属性“filter”,python,sqlalchemy,Python,Sqlalchemy,我有以下三门课: class Resource: id = Column(Integer, primary_key=True) path = Column(Text) data = Column(Binary) type = Column(Text) def set_resource(self, path, data, type): self.path = path self.data = data sel

我有以下三门课:

class Resource:
    id = Column(Integer, primary_key=True)
    path = Column(Text)
    data = Column(Binary)
    type = Column(Text)

    def set_resource(self, path, data, type):
        self.path = path
        self.data = data
        self.type = type

class EnvironmentResource(Base, Resource):
    __tablename__ = 'environment_resources'
    parent_id = Column(Integer, ForeignKey('environments.id', ondelete='CASCADE'))
    def __init__(self, path, data, type):
        self.set_resource(path, data, type)

class Environment(Base):
    __tablename__ = 'environments'
    id = Column(Integer, primary_key=True)
    identifier = Column(Text, unique=True)
    name = Column(Text)
    description = Column(Text)

    _resources = relationship("EnvironmentResource",
        cascade="all, delete-orphan",
        passive_deletes=True)
    _tools = relationship("Tool",
        cascade="all, delete-orphan",
        passive_deletes=True)

    def __init__(self, name, identifier, description):
        self.name = name
        self.identifier = identifier
        self.description = description

    def get_resource(self, path):
        return self._resources.filter(EnvironmentResource.path==path).first()
在调用get_resource时,我被告知'InstrumentedList'对象没有属性'filter'——我已经阅读了文档,不能完全理解这一点。我遗漏了什么,以便能够在“get_resource”方法中过滤与环境相对应的资源

PS:我知道get_资源将抛出一个异常,这是我希望它做的。

为了使用as with查询,您需要使用lazy='dynamic'对其进行配置。有关详细信息,请参见:


有人可以向n00bie数据库解释lazy='dynamic'的含义和作用吗?类似地,如果backref存在相同的问题,则需要将backref='items'替换为backref=db.backref'items',lazy='dynamic'。如果没有lazy='dynamic',则直接在env.environment\u资源上获得结果。但是使用lazy='dynamic',它会返回一个-youcando-streng.environment\u资源,它会给你一个SQL查询,你可以在上面加上过滤器等等
_resources = relationship("EnvironmentResource",
    cascade="all, delete-orphan",
    lazy='dynamic',
    passive_deletes=True)