I expected to be able to map both sides of the relationship from a  
resultset with the proper columns. However it appears to still lazy  
load all the child objects. Short example (works against trunk):

import pkg_resources
pkg_resources.require( "sqlalchemy" )
pkg_resources.require( "pysqlite" )

from sqlalchemy import *

# Setup classes, tables, mappers

metadata = BoundMetaData( 'sqlite:////tmp/test.db' )
metadata.engine.echo = True

class A( object ):
     pass

class B( object ):
     pass

A.table = Table( "table_a", metadata,
     Column( "id", Integer, primary_key=True),
     Column( "name", String(20) ) )

B.table = Table( "table_b", metadata,
     Column( "id", Integer, primary_key=True),
     Column( "name", String(20) ),
     Column( "table_a_id", Integer, ForeignKey( "table_a.id" ) ) )

mapper( B, B.table )
mapper( A, A.table, properties=dict( bs=relation( B, backref="a" ) ) )

metadata.create_all()

# Insert some stuff

session = create_session()

for i in range( 10 ):
     a = A()
     a.name = "A_%d" % i
     session.save( a )
     for j in range( 10 ):
         b = B()
         b.name= "B_%d" % i
         b.a = a
         session.save( b )
session.flush()
session.clear()

# Map from select

results = select( [ A.table, B.table ], A.c.id == B.c.table_a_id,  
use_labels=True ).execute()
some_as = class_mapper( A ).instances( results, session, with_options= 
[eagerload('bs')] )

# At this point many queries against 'b_table'

for a in some_as:
     list( a.bs )

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sqlalchemy
-~----------~----~----~----~------~----~------~--~---

Reply via email to