Very simple scenario
N users, each user can have 0 .. N - 1 friends (who are also users)
How can I model this in Java for AppEngine data store
Scenario to consider
- user x and user y become friends (so both need update their own status, in a transaction
Consider using a
Friendship
table with just two foreign keys,user1
anduser2
. An entry in this table models an social connection between two users. You could even add more columns to describe thetype
of this social relation.(or consider sfussenegger's answer ;) same idea but better presentation)
We've modeled user relations as a simple UserRelation entity:
Where RelationState is an enum, describing states (normally, there is more than friendship)
Actually, we also use this enum for authorizaton, e.g. on user profiles.
It's easiest to have two objects for each (symmetric) relationship (e.g. friendship as used on facebook) and only a single object for non-symmetric relationships (e.g. followers as used on twitter or blocked users). While this might look like overhead in the first place, using two objects certainly simplifies querying.
I think the AppEngine part itself should then be pretty straight forward.