if youre using postgres, just call the appropriate sequence whenever
you want, and assign that value to your non-committed object:
id = select([func.nextval('my_seq')], engine=db).scalar() # this
syntax will be improved soon....
myobject.id = id
doing an INSERT to get a primary key is going to affect the
database. if you open a transaction, thats one way to keep the data
from actually being committed, but thats not a great way just to get
a primary key, also wont really work on mysql/ISAM tables or sqlite.
why would you actually want to use a primary key for messaging
purposes, if that primary key doesnt actually exist yet ? doesnt
that invite error conditions to arise (i.e. one part of the app is
receiving inaccurate information) ?
On Mar 4, 2006, at 7:54 AM, Aaron Bickell wrote:
Hello,
What I'm trying to do is get the primary key for a brand new
object at the time I create it, rather than when I call
objectstore.commit(). I need the identifier when I create the
object for logging, and messaging purposes (amongst others). I
don't want to commit the transaction at this point, but I would
like to have the resultant object to be in 'sync' with the object
store. This is what I did to make that work:
User.mapper.table.insert(userDict).execute()
id = engine.last_inserted_ids()[0]
user = User.mapper.get(id)
Is there an easier way to do this that I totally missed?
Would it be possible to have a newly created object grab the next
sequence value at instantiation time or
be able to create an object and explicitly 'save' it? Save would
mean, execute it's insert statements against the database but not
commit the transaction. Thanks.
Aaron
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting
language
that extends applications into web and mobile media. Attend the
live webcast
and join the prime developer group breaking into this new coding
territory!
http://sel.as-us.falkag.net/sel?
cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users