this is related to my previous post about lazy loads....i just made a  
change in changeset 1638 so that if an object is not bound to a  
Session, or if the Session to which the object was bound has been  
garbage collected (as is the case in your example), its going to  
raise an exception.  which is less mysterious than "just returns a  
blank list".

(feel free to subscribe to the list ! )

On Jun 8, 2006, at 3:49 AM, Peter Davids wrote:

> Hi! SQLAlchemy is great! I have a question regarding create_session 
> () and
> lazy loading (using version 0.2.2). See comments in code. Could anyone
> explain this strange behavior to me? Thanks!
>
> -Peter
>
> from sqlalchemy import *
>
> class Address(object):
>
>     pass
>
> class Customer(object):
>
>     pass
>
> def test():
>     engine = create_engine("sqlite:///:memory:")
>     meta = BoundMetaData(engine)
>     customer_table = Table("customer", meta,
>       Column("id", Integer, primary_key=True),
>       Column("name", String),
>       Column("address", Integer, ForeignKey("address.id")))
>     address_table = Table("address", meta,
>       Column("id", Integer, primary_key=True),
>       Column("street", String))
>     meta.create_all()
>     address_table.insert().execute(id=1, street="Blabla 7")
>     address_table.insert().execute(id=2, street="Blabla 9")
>     customer_table.insert().execute(id=1, name="Mr. Smith", address=1)
>     customer_table.insert().execute(id=2, name="Mr. Brown", address=2)
>
>     Address.mapper = mapper(Address, address_table)
>     Customer.mapper = mapper(Customer, customer_table,  
> properties=dict(
>       addressobj = relation(Address, lazy=True)))
>
>     # this does not work using lazy loading (why?), but eager does
>     for c in create_session().query(Customer).select():
>       print c.id, c.name, c.addressobj
>
>     # however, assigning session to a variable first makes lazy  
> loading work
>     session = create_session()
>     for c in session.query(Customer).select():
>       print c.id, c.name, c.addressobj
>
> if __name__ == "__main__":
>     test()
>
> _______________________________________________
> Sqlalchemy-users mailing list
> Sqlalchemy-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users



_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to