2016-01-21 26 views
0

設置:Parse.com JS SDK多個與嵌套查詢包括

  • 所述的產品,其具有一個指針指向品牌和一個指針到店
  • 一個品牌,具有名稱,..
  • 一個店,有名稱,城市,...

查詢應該得到基於一個過濾器的所有產品,即:

  • 零,一個或多個品牌的IDS到product.brand.id應該相匹配,product.shop.id應符合

我的ID

  • 零,一個或多個店鋪ID在一個陣列,所以基本上我想要的到底是:

    SELECT * FROM products 
    WHERE product.shop.id IS IN shop_ids && product.brand.id IS IN brand_ids 
    

    我無法弄清楚如何也要做,我試過下面讓其中包括品牌標識的所有產品,作品。 的包括不工作,ALSO品牌的旁邊,它應檢查該產品是給定的店鋪ID

    的列表中
      for (var i = 0; i < brand_ids.length; i++) 
          { 
           var query = new Parse.Query(product); 
           var brand = new Brand(); 
           brand.id = brand_ids[i]; 
           query.equalTo('brand', brand); 
           query.include('brand'); 
           query.include('shop'); //TODO: where shop is one of [ids] 
    
           queries.push(query); 
          }; 
    
  • 回答

    0

    你的代碼基本上創建查詢列表和他們每個人都可以只匹配一個ID。您需要使用containedIn API https://parse.com/docs/js/api/classes/Parse.Query.html#methods_containedIn。嘗試下面的代碼:

    var query = new Parse.Query(product); 
    var brands = []; 
    for (var i = 0; i < brand_ids.length; i++) { 
        var brand = new Brand(); 
        brand.id = brand_ids[i]; 
        brands.push(brand); 
    }; 
    query.containedIn('brand', brands); 
    query.include('brand'); 
    query.include('shop'); //TODO: where shop is one of [ids] 
    query.find(); 
    
    +0

    謝謝,這工作,我不得不這樣做的商店。 –