Hi hawkett, Currently, you only have a couple of options: You can set the reference to None instead of to the object itself, and then code your app to recognise the two situations as identical, or you can use two transactions: The first to create the entity, and the second to set the key.
-Nick Johnson On Sat, May 23, 2009 at 11:48 AM, hawkett <hawk...@gmail.com> wrote: > > Hi, > > I have a situation where I need an entity to store a reference to > itself, in much the same way as the value of the 'parent' field for > the root of an entity group stores it's own key. As with entity > groups, its not all records that point to themselves, but some do, and > in my use case it means much the same thing - the root of the tree. > > The problem is that I also need to create such a record inside a > transaction, and transactions have the constraint that you can't > update the same record twice. I need to update the record twice - the > first time to get the key value generated, and the second time to set > that key as the value of the self reference. > > The most obvious solution is to use a key_name to generate a key > without writing to the database, however I will be writing many > thousands of these entities, and coming up with my own unique naming > process when GAE already has one doesn't seem right. > > So I guess the first question is whether there is an approach I am > missing here. > > The second would be to find out whether any of the following are > likely to make it into GAE anytime soon - > > 1. Default to self for SelfReference - i.e. pretty much what happens > with the 'parent' attribute > > class Story(db.Model): > title = db.StringProperty() > selfRef = db.SelfReferenceProperty(default=__self__) > > > 2. A 'self' value when creating a Model instance > > class Story(db.Model): > title = db.StringProperty() > selfRef = db.SelfReferenceProperty() > > s=Story(title="Some title", selfRef="__self__") > s.put() > > 3. Access to the keyFactory > > key = db.generateKey() > > s=Story(key_name=key, title="Some title", author="some author") > s.selfRef = s.key() > s.put() > > 4. The ability to update the same entity multiple times in the same > transaction > > Thanks, > > Colin > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appengine@googlegroups.com To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~----------~----~----~----~------~----~------~--~---