不删除子句“ in”中的对象列表

时间:2018-11-27 10:05:12

标签: android realm

Android Studio 3.2,Realm 5.8.0

在Realm中,我有3个带有{​​{1}}的商家。

现在,我删除所有带有id=1,2,3的商家

因此,我为此使用了“ ids= 1,2”子句。

以下代码段:

in

在logcat中,您可以看到:

   public static void updateList(final List<Merchant> thatMerchantsList) {
     Realm realm = Realm.getDefaultInstance();
            try {
                realm.executeTransaction(new Realm.Transaction() {
                    @Override
                    public void execute(Realm realm) {
                      Long[] idsToDeleteArray = new 
                      Long[itemNotExistInThatMerchants.size()];
                      for (int index = 0; index <                          
                         itemNotExistInThatMerchants.size(); index++) {
                          Merchant merchant = 
                          itemNotExistInThatMerchants.get(index);
                          idsToDeleteArray[index] = merchant.getId();
                       }

                      RealmResults<Merchant> localMerchantsForDelete = 
                           realm.where(Merchant.class).in(Merchant.ID, 
                              idsToDeleteArray).findAll();
                      boolean isDelete = 
                         localMerchantsForDelete.deleteAllFromRealm();
                      Debug.d(TAG, "updateMerchantList: idsToDeleteArray =  " + Arrays.toString(idsToDeleteArray)
                          + " -> localMerchantsForDelete_size = " + localMerchantsForDelete.size() + " -> isDelete = " + isDelete);
                     }
                });
            } finally {
                realm.close();
                Debug.d(TAG, "updateMerchantList: finish");
            }
}

您会看到idsToDeleteArray = [1, 2] -> localMerchantsForDelete_size = 0 -> isDelete = true 。为什么?

结果这两个商人没有从Realm中删除。

0 个答案:

没有答案