开发者

select some fields in eagerload

开发者 https://www.devze.com 2023-02-05 09:22 出处:网络
I have two tables: class Auto(Base): __tablename__ = \"auto\" id = Column(Integer, primary_key=True) added = Column(DateTime())

I have two tables:

class Auto(Base):

    __tablename__ = "auto"

    id = Column(Integer, primary_key=True)
    added = Column(DateTime())

and

class Url(Base):

    __tablename__ = "url"

    id = Column(Integer, primary_key=True)
    added = Column(DateTime())
    auto_id = Column(Integer, ForeignKey('auto.id'))开发者_StackOverflow
    url = Column(Unicode(500))
    content = Column(UnicodeText())

    auto = relation('Auto', backref=backref('url', order_by=id))

I selecting data with

Session.query(Auto).options(eagerload('url')).limit(20)

In select statement i get all fields relative to Auto and Url tables, but i want to select only some results (Auto.id, Auto.added, Url.id, Url.added). Problem is what in Url.content store large amount of data.


Like you are using option eagerload() for relations, there is an option defer() for column properties to disable loading them untill they are accessed:

session.query(Auto).options(joinedload('url'), defer('url.content')).limit(20)
0

精彩评论

暂无评论...
验证码 换一张
取 消