Sorry, I forgot to add that the mappers A and B must have a relation()
specified in order for unit of work to determine the order of
operations. this has always been the case in all versions.
illustrated in the attached script.
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---
from sqlalchemy import *
from sqlalchemy.orm import *
engine = create_engine('sqlite://', echo=True)
metadata = MetaData(engine)
engine.execute("""
CREATE TABLE A (
x INTEGER PRIMARY KEY
)""")
engine.execute("""CREATE TABLE B (
y INTEGER PRIMARY KEY REFERENCES A(x)
)
""")
tableA = Table('A', metadata, autoload=True)
tableB = Table('B', metadata, autoload=True)
class A(object):
def __init__(self, x):
self.x = x
class B(object):
def __init__(self, y):
self.y = y
mapper(A, tableA, properties={
'b':relation(B)
})
sess = create_session()
mapper(B, tableB)
a = A(x=10)
sess.save(a)
b = B(y=10)
sess.save(b)
sess.flush()
On Nov 9, 2007, at 10:42 AM, Manlio Perillo wrote:
>
> Hi.
>
> It seems that from SQLAlchemy 0.3.7(?) the unit of work, after a
> flush,
> executes the SQL operations in a different order.
>
> As an example, assuming this schema
>
> CREATE TABLE A (
> x INTEGER PRIMARY KEY
> );
>
> CREATE TABLE B (
> y INTEGER PRIMARY KEY REFERENCES A(x)
> );
>
>
> in 0.36 I can execute, in a session transaction:
> a = A(x=10)
> sess.save(a)
>
> b = B(x=10)
> sess.save(b)
>
> sess.flush()
>
>
> This no longer works on 0.3.10, where I need to do a flush after `a`
> creation.
>
>
>
> Is this a feature?
> Is it possible to force the unit of work to execute queries in the
> right
> order, in order to avoid an intermediate flush?
>
>
>
> Thanks Manlio Perillo
>
> --~--~---------~--~----~------------~-------~--~----~
> 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?hl=en
> -~----------~----~----~----~------~----~------~--~---
>