Thanks, sorry must have missed that in the docs.

On Tue, May 18, 2010 at 1:51 AM, Michael Bayer <mike...@zzzcomputing.com> wrote:
> set expire_on_commit=False on your sessionmaker.
>
>
> On May 17, 2010, at 6:20 AM, Julian Scheid wrote:
>
>> Is there a way to avoid the SELECT statement issued by the following
>> test case, i.e. to have some_a "survive" the commit?
>>
>> --- 8< ---
>>
>> from sqlalchemy import create_engine, Column, Integer, String, ForeignKey
>> from sqlalchemy.orm import sessionmaker, relation
>> from sqlalchemy.ext.declarative import declarative_base
>>
>> engine = create_engine("sqlite://", echo=True)
>> session = sessionmaker(bind=engine)()
>>
>> Base = declarative_base()
>>
>> class A(Base):
>>    __tablename__ = 'a'
>>    id = Column(Integer, primary_key=True)
>>
>> class B(Base):
>>    __tablename__ = 'b'
>>    id = Column(Integer, primary_key=True)
>>    a_id = Column(Integer, ForeignKey('a.id'), nullable = False)
>>    a = relation(A)
>>
>> Base.metadata.create_all(bind=engine)
>>
>> some_a = A()
>> session.add(some_a)
>> session.commit()
>>
>> some_b = B(a=some_a)
>> session.add(some_b)
>> session.commit()
>>
>> --- >8 ---
>>
>> # Table creation etc omitted
>>
>> 2010-05-17 22:12:06,533 INFO sqlalchemy.engine.base.Engine.0x...41d0 BEGIN
>> 2010-05-17 22:12:06,534 INFO sqlalchemy.engine.base.Engine.0x...41d0
>> INSERT INTO a DEFAULT VALUES
>> 2010-05-17 22:12:06,534 INFO sqlalchemy.engine.base.Engine.0x...41d0 []
>> 2010-05-17 22:12:06,534 INFO sqlalchemy.engine.base.Engine.0x...41d0 COMMIT
>> 2010-05-17 22:12:06,535 INFO sqlalchemy.engine.base.Engine.0x...41d0 BEGIN
>> 2010-05-17 22:12:06,536 INFO sqlalchemy.engine.base.Engine.0x...41d0
>> SELECT a.id AS a_id
>> FROM a
>> WHERE a.id = ?
>>   # <-- I'd like to avoid this
>> 2010-05-17 22:12:06,536 INFO sqlalchemy.engine.base.Engine.0x...41d0 [1]
>> 2010-05-17 22:12:06,537 INFO sqlalchemy.engine.base.Engine.0x...41d0
>> INSERT INTO b (a_id) VALUES (?)
>> 2010-05-17 22:12:06,537 INFO sqlalchemy.engine.base.Engine.0x...41d0 [1]
>> 2010-05-17 22:12:06,537 INFO sqlalchemy.engine.base.Engine.0x...41d0 COMMIT
>>
>> --- 8< ---
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "sqlalchemy" group.
>> To post to this group, send email to sqlalch...@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> sqlalchemy+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/sqlalchemy?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
>
>

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

Reply via email to