我有以下数据模型:
class StadiumOccupant {
String stadiumname;
String username;
}
class Friend {
String username;
String friendname;
}
我想在体育场找到所有也是我朋友的用户。我可以这样做:
List<String> friendsAtStadium;
String stadiumId = 'xyz';
List<Friend> friends = select from Friend where username = 'me';
for (Friend friend : friends) {
List<StadiumOccupant> friendAtStadium =
select from StadiumOccupant where
stadiumname = stadiumId and
username = friend.friendname;
friendsAtStadium.addAll(friendAtStadium);
}
这可以处理非常少量的对象。一旦用户拥有多个朋友,这将不起作用。应用引擎上有解决方案吗?我想不出一个表现好的。
谢谢
-------- 一些样本数据--------
Friend { john, tim }
Friend { john, mary }
Friend { mary, frank }
StadiumOccupant { abc, tim }
StadiumOccupant { abc, frank }
StadiumOccupant { abc, kim }
所以如果我是用户 'john',我的朋友是:{ tim, mary }。如果我使用 Stadiumname='abc' 运行体育场查询,我应该返回 { tim }。