Hi, With the example of threaded comments, I'm not entirely convinced that there would be anything wrong with doing a SelfReferenceProperty to store the link between a reply to a comment and the original comment.
Let me explain to you how I might approach this problem, and obviously you can modify this for your own needs. I would probably turn threading off by default, allowing comments to be displayed relatively chronologically, but also allowing the user to view comment threads as he or she desired. My comment model would probably be something like: class Comment(db.Model) reply_to = db.SelfReferenceProperty() has_reply = db.BooleanProperty(default=False) comment_index = db.StringProperty() author = db.UserProperty() comment = db.TextProperty() post_time = db.DateTimeProperty() I would just use the system that Brett discussed in Building Scalable Web Application ( http://sites.google.com/site/io/building-scalable-web-applications-with-google-app-engine) to ensure that all comments were more or less sorted. To just view in order, I would sort by the comment index, and be done with that. A user could either reply to a comment, or post an entirely new comment. If a person replied to a comment, I would store with the reply comment a reference to the 'parent' comment (here I don't mean parent in terms of txns). In the 'parent' comment, I would store as a boolean property parent_comment.has_reply=True. This is just for ease, so when rendering the template, instead of doing a query for back references to the comment, I could just display a link below the comment 'show comment thread'. When the user clicked on 'show comment thread' you could just do a back reference query on all of the replies to that comment. You'd fetch the first, say, 11 of those comments, display the first 10, and a link to show more if the 11th existed. This could work to have comments nested as deep as you like. All of the replies could also have replies, and you could display a sub-thread just by checking to see if the reply has a reply. Hopefully this response makes sense. I'm sure there are other approaches to this problem, but I'm fairly certain this could work well, and would be easy to render and query for as well as being fairly efficient. -Marzia On Fri, Oct 31, 2008 at 2:33 PM, Chris Tan <[EMAIL PROTECTED]> wrote: > > Thanks for the heads up on that interesting method. > > Just wondering, from your comment in the other thread: > > "Or, stick with the lexical path but use the full byte rather than > decimal to store the number.. then just 2 bytes give you a max of 64k > comments per depth and 200+ deep. " > > The sort order for StringProperty is in Unicode, so wouldn't you have > to use > an something like UTF-8? > > > Some pros of this method: > - Fast query for children > - Possible to reconstruct hierarchy > > Cons: > - Limited depth > - Need to do query for siblings before setting the path > - Somewhat complex. Need to increment Unicode character > > > > On Oct 31, 3:34 am, Anthony <[EMAIL PROTECTED]> wrote: > > Store all the parent ids as a hierarchy in a string... > > > > h="id1/id2/" > > h="id1/id2/id3" > > h="id1/id2/id3/id4" > > h="id5/" > > h="id5/id6" > > > > You can then filter WHERE h > "id1/" and h < "id5/" to get all > > children of id1. > > > > Or you can use entity groups & ancestors. > > > > More details here... > http://groups.google.com/group/google-appengine/browse_thread/thread/... > > > > On Oct 31, 8:31 am, Chris Tan <[EMAIL PROTECTED]> wrote: > > > > > I'm wondering how other people have been modeling hierarchical > > > information > > > such as nested comments. > > > > > My first thought was to do something like this: > > > > > class Comment(db.Model): > > > reply_to = db.SelfReferenceProperty(collection_name="replies") > > > author = db.UserProperty() > > > content = db.TextProperty() > > > > > However, this isn't scalable, as a query is made for every > > > comment in the thread. > > > > > Any ideas? > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en -~----------~----~----~----~------~----~------~--~---
