[PEAK] strategy question about generating oids
Phillip J. Eby
pje at telecommunity.com
Wed Oct 27 17:56:07 EDT 2004
At 04:45 PM 10/27/04 -0400, R. David Murray wrote:
>I have some database tables for which I want to have an OID that
>is a monotonically increasing integer for each new record. What's
>the best strategy for doing this in PEAK? My specific question, I
>guess, is how do I (and should I be trying to) avoid doing a flush()
>after creating a new object just so the id will get assigned so
>it can be used as a foreign key elsewhere?
You don't have to flush manually, as long as you use oidFor() to get the
foreign key.
That is, in the _save() method of a DM for an object that refers to other
objects, you should get the OID by calling oidFor() on the DM for the
referenced object. This will take care of flushing the object for you, if
it doesn't already have an OID.
(It should already go without saying that there shouldn't be any client
code that sees or manipulates OIDs directly.)
More information about the PEAK
mailing list