2016-02-03 48 views
0

我總共有三個班級來管理經銷商選定的產品數據。擴展RealmObjectIN在領域運作

1) Dealers 
    DealerId 
    DealerName 

2) Products 
    ProductId 
    ProductName 
3) DealerProduct (contains the mapping between Dealers's selected product) 
    DealerId 
    ProudctId 

類現在我想用領域

select * from Products where productId IN ('P101','P102'); 

火查詢是否有辦法在境界火IN操作

回答

1

您可以使用RealmQuery.or()

RealmResults<Products> products = realm.where(Products.class) 
      .equalTo("productId", "P101") 
      .or().equalTo("productId", "P102") 
      .findAll(); 
+0

所以如果我有整個數組的大小爲10那麼還必須使用上面的表達式等於10倍? – Hunt

+0

我終於寫了'String arr [] = {「C0001」,「C0002」,「C0702」};對於(int i = 0; i <3; i ++){ query.equalTo(「dealerID」,arr [i])。或(); }' – Hunt

+0

沒錯,那根本不方便......我在realm-java repo中創建了一個問題,https://github.com/realm/realm-java/issues/2230。我們會盡量讓這個案例更容易。非常感謝您的反饋! – beeender