Attached is a script that attempts to imitate as close as I can tell  
to what you are asking (and the end result is correct).   Modify it to  
illustrate your exact issue.


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

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.orm.session import Session
from sqlalchemy.ext.declarative import declarative_base

engine = create_engine('sqlite://', echo=True)

Base = declarative_base()

class Parent(Base):
    __tablename__ = 'parent'
    
    id = Column(Integer, primary_key=True)
    data = Column(String)
    children = relation("Child", lazy=False)
    
class Child(Base):
    __tablename__ = 'child'
    
    id = Column(Integer, primary_key=True)
    data = Column(String)
    parent_id = Column(Integer, ForeignKey('parent.id'))

Base.metadata.create_all(engine)

engine.execute(Parent.__table__.insert(), {'id':1, 'data':'parent1'})
engine.execute(Child.__table__.insert(), {'id':1, 'data':'child1', 'parent_id':1})
engine.execute(Child.__table__.insert(), {'id':2, 'data':'child2', 'parent_id':1})


session = Session(bind=engine, autoflush=False,
          _enable_transaction_accounting=False, autocommit=True,
          weak_identity_map=True)
          
parent = session.query(Parent).first()
children = session.query(Child).all()
assert parent.children == children

query = session.query(Parent)
query = query.with_lockmode('update')
query = query.options(lazyload(Parent.children))
query = query.filter_by(id=parent.id)
query = query.populate_existing()
rows = query.all()

parent = rows[0]
assert parent.children == children


On Sep 27, 2008, at 1:52 PM, Mike Bernson wrote:

>
> I have a problem with row coming back form mapped class that has  
> relations.
>
> The session is created with:
>
> self.session = Session(bind=self._engine, autoflush=False,
>           _enable_transaction_accounting=False, autocommit=True,
>           weak_identity_map=True)
>
>
> The problem occurs with instance on that have already been loaded  
> and the query
> ask for lazyload of some of the relations.  The first query load a  
> bunch of row. The
> second query does  the follow:
>
> query = session.query(mapped_class)
> query = query.with_lockmode('update')
> query = query.options(lazyload(relation1)
> query = query.options(lazyload(relation2)
> query = query.filter_by(id=234)
> query = query.populate_existing()
>
> rows = query.all()
>
> In the rows relation1 and relation2 both are not none. All the data  
> in relation1 and relation2 is
> None. If I remove the lazyload and try it I get data in relation1  
> and relation2.
>
> What I am trying to do is  update the instance to match the data and  
> create locks for
> all but the tables that are lazyload.
>
> There are no other references to relation1 and relation2.
>
> I have not verified but It look like if a relation has other  
> references the relation has data in it
> columns.
> This happens in both 0.5b3 and 0.5rc1.
>
>
>
>
> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google  
> Groups "sqlalchemy" group.
> To post to this group, send email to sqlalchemy@googlegroups.com
> To unsubscribe from this group, send email to [EMAIL PROTECTED]
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en
> -~----------~----~----~----~------~----~------~--~---
>

Reply via email to