mysql
  • database
  • google-app-engine
  • 2012-04-14 98 views 1 likes 
    1

    我有一个名为RelatedUsers与模型有三个属性:如何做一个OR查询谷歌应用程序引擎

    firstUserId 
    secondUserId 
    relationshipStatus 
    

    我从MySQL未来在那里我会做到这一点:

    mysql_query("SELECT * FROM relatedUsers WHERE (firstUserId='$originatorId' 
    AND secondUserId='$recipientId') OR (firstUserId='$recipientId' 
    AND secondUserId='$originatorId')"); 
    

    Google App Engine如何做到这一点?我找不到任何类似的案例在线..

    +2

    你不知道。数据存储不支持它。 – geoffspear 2012-04-14 21:43:32

    +0

    任何OR的一般都不受支持? – Snowman 2012-04-14 21:53:54

    +0

    无论如何,你基本上都会要求两个不同的查询。看起来您的查询设计为每个返回一条记录,但在这种情况下,使用两个用户的组合用户ID作为您的“关联用户”实体的关键名称会更有意义。然后,您可以使用批处理获取它们。 – 2012-04-15 01:48:13

    回答

    2

    通过运行几个关键的查询,然后获取密钥。

    from google.appengine.ext import ndb 
    
    class User(ndb.Model): 
        email = db.StringProperty() 
    
    
    options = ndb.QueryOptions(keys_only=True) 
    condition_1 = ndb.Query(User, options=options).filter(User.email == "[email protected]") 
    condition_1 = ndb.Query(User, options=options).filter(User.email == "[email protected]") 
    
    key_list = list(set(list(condition_1) + list(condition_2))) 
    
    mom_and_dad = ndb.get_multi(key_list) 
    

    如果你必须订购它们,你将不得不在内存中这样做。

    /从内存中完成:)

    相关问题