Hi there.
I'm moving some SQLObject code to SQLAlchemy, and I can't work out how to do
something. I'm sure it's trivially simple, I just can't see anything like it
in the documentation, and my trial-and-error approach hasn't worked so far.
A bare-bones is described below:
Assume two name<->id mapping tables and a single join table "ForeignKey"-ed to
these:
a = Table ( 'a',
Column('id', Integer, primary_key=True),
Column('name', String(256)))
b = Table ( 'b',
Column('id', Integer, primary_key=True),
Column('name', String(256)))
ab = Table ( 'ab',
Column('a_id', Integer, ForeignKey ( "a.id" )),
Column('b_id', Integer, ForeignKey ( "b.id" )))
Now assume I am given two *name* values, and these are drawn from a and b, and
I want to insert a row into ab containing the two id values. In plain SQL, I
would do this:
insert into ab ( a_id, b_id )
select a.id, b.id from a, b where a.name = "foo" and b.name = "bar"
In SQLObject I suspect this isn't even possible: retrieving the row objects
using a byName() lookup will simply perform SELECTs. However, I'm keen to
find a more efficient way of doing this since I'd like to insert multiple
rows on one leg of the SELECT, like this:
insert into ab ( a_id, b_id )
select a.id, b.id from a, b where a.name = "foo" and b.name in
( "bar", "baz", ... )
Can a kind Alchemist please prod me in the right direction?
Thanks,
Ricky
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users