load_only as stated in http://docs.sqlalchemy.org/en/latest/orm/loading_columns.html does the following: "An arbitrary set of columns can be selected as “load only” columns, which will be loaded *while deferring all other columns* on a given entity..."
However, joined relationships are not affected by this, meaning that the produced sql still joins all 'joined' relationships Consider the following example: import sqlalchemy as sa from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class Foo(Base): __tablename__ = 'foo' id = sa.Column(sa.Integer, primary_key=True) bars = sa.orm.relationship("Bar", lazy="joined") class Bar(Base): __tablename__ = 'bar' id = sa.Column(sa.Integer, primary_key=True) foo_id = sa.Column(sa.Integer, sa.ForeignKey('foo.id')) baz = sa.Column(sa.Integer) e = sa.create_engine("sqlite://", echo=True) session = sa.orm.Session(e) session.query(Foo).options(sa.orm.load_only('id')).all() The query produced is the following: SELECT foo.id AS foo_id, bar_1.id AS bar_1_id, bar_1.foo_id AS bar_1_foo_id, bar_1.baz AS bar_1_baz FROM foo LEFT OUTER JOIN bar AS bar_1 ON foo.id = bar_1.foo_id I understand that I can use the lazyload option to prevent the join but I thought it would be nice if the load_only handled it out-of-the-box... -- 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.