I thought it will help getting all the memberships (without doing an extra query). With each group, I always want the memberships with it as well.
In my case, I will get the complete group information (including all memberships) with just one query : memberships = Membership.all().filter(person = me) // for each m in memberships, m.group.memberships is pre filled. In your case, I will have to do the following memberships = Membership.all().filter(person = me) for each m in memberships: Membership.all().filter(group = m.group) // this will return m.group.memberships Am I missing something with my approach? Maybe the query is done on the back end anyway? Please advise. On Tue, Sep 8, 2009 at 1:49 PM, Jason (Google) <apija...@google.com> wrote: > Since you've created a new kind (Membership) to model the relationship > between Person and Group, I'm a bit confused on why you're using a > relationship between Group and Membership. Shouldn't Group and Membership be > independent? > > class Person { > ... > } > > class Group { > ... > } > > class Membership { > Key key; // key name is concatenated IDs of Person and Group > ... > } > > Solution 1 is less work and less code but my feeling is that, as your code > gets older, it could become more of a problem, especially if other > programmers start committing and don't understand how or why you're > concatenating the IDs to store membership information. If this is likely, I > would opt for solution 2. > > If you go ahead with solution 1, you can take advantage of one of the more > recent 1.2.5 features, allocateIds(), which allows you to set aside one or > more IDs for entities yet to be created. It's only exposed in the low-level > API at this point: > > > http://code.google.com/appengine/docs/java/javadoc/com/google/appengine/api/datastore/DatastoreService.html > > - Jason > > > On Sun, Sep 6, 2009 at 11:18 PM, Sam Walker <am.sam.wal...@gmail.com>wrote: > >> In 1, another problem is that I may not know the Keys of A and B at the >> point of creation. For example, lets say I am doing something like this: >> >> class Person { >> } >> >> class Group { >> @Persistent(mappedBy = "group") >> ArrayList<Membership> memberships; >> } >> >> class Membership { >> Key person; >> Group group; >> } >> >> >> Now I would do: >> Group g = new Group(); >> while(...) { >> Membership m = new Membership(); >> g.memberships.add(m); >> } >> pm.makePersistent(g); >> >> Now, when I create membership, I dont have the Group key (I do have the >> person key), I can't really use it to create a new derived key for >> membership. Or am I missing something? >> >> >> On Sun, Sep 6, 2009 at 11:04 PM, Sam Walker <am.sam.wal...@gmail.com>wrote: >> >>> Lets say there is a relationship between Entities A and B, and I want to >>> model it with Entity C. >>> >>> Two ways: >>> 1. Use concatenated Key of A and B for Key of C. Data model will ensure >>> there are no duplicates. >>> 2. Use autogenerated Key and make sure you do not duplicate A B >>> relationship in code. >>> >>> Which one would you choose? In 1, is a simple concatenation the best way >>> to go about it? >>> >> >> >> >> > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to google-appengine-java@googlegroups.com To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en -~----------~----~----~----~------~----~------~--~---