[Sqlalchemy-tickets] [sqlalchemy] #2287: mapper.order_by incorrectly placed with subqueryload
Brought to you by:
zzzeek
From: sqlalchemy <mi...@zz...> - 2011-09-27 15:23:12
|
#2287: mapper.order_by incorrectly placed with subqueryload --------------------+------------------------------------------------------- Reporter: zzzeek | Owner: zzzeek Type: defect | Status: new Priority: medium | Milestone: 0.6.9 Component: orm | Severity: major - 1-3 hours Keywords: | Status_field: needs review --------------------+------------------------------------------------------- {{{ #!python import sqlalchemy as sa import sqlalchemy.orm as saorm from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class Master(Base): __tablename__ = 'master' id = sa.Column(sa.Integer, primary_key=True, autoincrement=True) dummy = sa.Column(sa.Integer) __mapper_args__ = {'order_by': sa.desc(id)} class Detail(Base): __tablename__ = 'detail' id = sa.Column(sa.Integer, primary_key=True, autoincrement=True) master_id = sa.Column(sa.Integer, sa.ForeignKey(Master.id)) master = saorm.relationship(Master, backref='details') def test(): dburi = 'sqlite://' engine = sa.create_engine(dburi, echo=True) Base.metadata.drop_all(bind=engine) Base.metadata.create_all(bind=engine) session = saorm.create_session(bind=engine) session.begin() # Insert 5 masters, each with 1 detail for i in range(5): master = Master(dummy=i) master.details.append(Detail()) session.add(master) session.commit() session.close() # Load back 2 masters, using subqueryload to load the detail # rows. If you uncomment the '.order_by' line here, the test # passes. master_query = (session.query(Master) #.order_by(sa.desc(Master.id)) .limit(2) .options(saorm.subqueryload('details'))) # Display the details for each master for item in master_query: print 'Master %s: %s' % (item.id, item.details), if len(item.details) == 0: print 'FAIL' else: print 'PASS' if __name__ == '__main__': test() }}} -- Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2287> sqlalchemy <http://www.sqlalchemy.org/> The Database Toolkit for Python |