Hi,

I am trying to understand the way to create a many to many
relationship in datastore. Let me take an example to start with.

Suppose I have users and communities as two entities. A user can join
as many communities as he wants and a community can have a lot of
users.

------------------                -------------------------
|                 |               |                        |
|   USER     |  m  ---  n  |  COMMUNITY  |
|                 |               |                        |
------------------                -------------------------
 First way of doing it
-------------------------------
class User {
String emailID  // primary key for user
List<Key> communitiesJoined
......
}

class Community {
Key communityID  // primary key for community
List<String> usersInCommunity

}

User Joins community ---
user.communitiesJoined.add(coummunityiD)
                     &&
community.usersInCommunity.add(userID)

Get Communities Joined By User --
user.communitiesJoined

Get Users in a community --
community.usersInCommnity


Second way
---------------------
class User {
String emailID // primary key for user
}

class Community {
Key communityID // primay key for community
}

class UserCommunityMapping {
String emailID
Key communityID
}

User Joins community ---
UserCommunityMapping ucm = new UserCommunityMapping()
ucm.emailID = user.emailID
ucm.communityID = community.communityID

Get Communities Joined By User --
select emailID from UserCommunityMapping where communityID =
coummunity.communityID

Get Users in a community --
select coummunityID from UserCommunityMapping where emailID =
user.userID

Now, can somebody tell me which is the better way to do it in
appstore? Below are the categories.

Performance during query?
Memory utilization?
Easy way to query?

If there is any other way, you can share that as well.

Thanks in advance.

-- 
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.

Reply via email to