session.query(Parent).options(defaultload("children").load_only("cheap_column"))

or really if you want to cut out "expensive_column"

session.query(Parent).options(defaultload("children").defer("expensive_column"))

http://docs.sqlalchemy.org/en/rel_0_9/orm/mapper_config.html#deferred



On May 10, 2014, at 6:39 PM, Seth <seedifferen...@gmail.com> wrote:

> Is there any way to get SQLAlchemy to only load specific columns through a 
> relationship()?
> 
> For example, with this scenario:
> 
> class Parent(Base):
>     __tablename__ = 'parent'
>     id = Column(Integer, primary_key=True)
>     children = relationship("Child", lazy='joined')
> 
> class Child(Base):
>     __tablename__ = 'child'
>     id = Column(Integer, primary_key=True)
>     parent_id = Column(Integer, ForeignKey('parent.id'))
>     cheap_column = Column(Unicode(10))
>     expensive_column = Column(LargeBinary)
> 
> I'd like Child to get lazily joined when Parent is loaded, but only with 
> Child's "cheap_column" and not it's "expensive_column".
> 
> Thanks,
> Seth
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to