Re: [Modeling-users] self.getId()
Status: Abandoned
Brought to you by:
sbigaret
From: Sebastien B. <sbi...@us...> - 2003-03-18 01:22:49
|
[snip] > >=20 > > You are using getId() (returning article._id) instead of getID() > > (returning the PK value stored in its GlobalID) ! > >=20 > >=20 > > However, we have a bug here: Article's PK did not get its value. >=20 >=20 > Yeah you got it :)=20 > If don't use the id as classProperty as said in the doc, and use=20 > the getID() helper sent before on the list it works well :)=20 I included a small patch at the end of the message to solve this issue --I'll make the unittest tomorrow and will correct this on the cvs rep. Now article._id should get its value as expected after ec.saveChanges(), if it's set as a class property. > I guess I win one more point in my debugging level :)=20 . The Evil Bug is struck down by a Mighty Patch=20 . You find an Inquisition Helmet +22 in the Evil Bug's treasure room ;) Thanks for the report, hopefully everything is ok now. BTW and back to your original question, why don't you use GlobalIDs rather than raw id number? This needs some pre- and post-processing if you need to pass them as strings in a http POST e.g., but you'll gain a generic scheme then. I remember using this transformation you might find handy: KeyGlobalID -> '<entityName>#<pk1name>#<pk1value>[#...]' and back (splitting with '#') i.e. something like that: def gid_to_str(gid): if gid.isTemporary(): raise ValueError, 'TemporaryGlobalIDs are not supported' gid_str=3Dgid.entityName() for pk,value in gid.keyValues().items(): gid_str+=3D'#%s#%s'%(pk, value) return gid_str =20=20=20=20=20=20 def str_to_gid(str): import string l=3Dstring.split(gid_str, '#') l.reverse() d=3D{} name=3Dl.pop() while l: d.setdefault(l.pop(), int(l.pop())) from Modeling.GlobalID import KeyGlobalID return KeyGlobalID(name, d) You then just have to request ec.faultForGlobalID() with the gid and you = get your object back. This does not work with temporary GlobalIDs, but if you're not going to use any sessioning mechanism as stated in your first message then you'll probably do not need to refer to inserted but unsaved objects! -- S=E9bastien. ------------------------------------------------------------------------ Index: EditingContext.py =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/modeling/ProjectModeling/Modeling/EditingContext.py,v retrieving revision 1.21 diff -c -r1.21 EditingContext.py *** EditingContext.py 12 Mar 2003 15:45:54 -0000 1.21 --- EditingContext.py 18 Mar 2003 00:29:39 -0000 *************** *** 1360,1365 **** --- 1360,1372 ---- self.recordObject(obj, key_gid) db=3Dself.rootObjectStore().objectStoreForObject(obj).database() db.incrementSnapshotCountForGlobalID(key_gid) + # time to update the object if a PK is set as class properties + from ModelSet import defaultModelSet + entity=3DdefaultModelSet().entityNamed(obj.entityName()) + pk_values=3Dkey_gid.keyValues() + for pk in entity.primaryKeyAttributes(): + if pk.isClassProperty(): + obj.takeStoredValueForKey(pk_values[pk.name()], pk.name()) else: obj=3Dself.objectForGlobalID(gid) new_gid=3Dnotification.userInfo().get(gid) ------------------------------------------------------------------------ |