在同一 属性 上发布更新领域

Issue updating Realm on same property

我有一个类似

的列表
 List<ChatMessage> l = realm.where(ChatMessage.class).equalTo("msg_receive_status", "0").findAll();

现在我想要的是 "msg_recieve_status" = 1

所以我尝试了,

    int count = l.size();
    realm.beginTransaction();
    for (int i = 0; i < count; i++) {
        ChatMessage m = l.get(i);
        m.setMsg_receive_status("1");
    }
    realm.copyToRealmOrUpdate(l);
    realm.commitTransaction();

但根本不起作用。

I think msg_receive_status is updating RealmList real time. and that's cause the problem.

您 运行 遇到了问题,因为查询结果是 "live",即它始终是最新的。我们正在为下一个版本合并修复程序:https://github.com/realm/realm-java/pull/2124

这里描述了一个解决方法:https://github.com/realm/realm-java/issues/640#issuecomment-103798064

在你的情况下转化为:

List<ChatMessage> l = realm.where(ChatMessage.class).equalTo("msg_receive_status", "0").findAll();

realm.beginTransaction();
for (int i = l.size() -1; i >=0; i--) {
   l.get(i).setMsg_receive_status("1");
}
realm.commitTransaction();