gpt4 book ai didi

realm - 无法删除 Realm 用户

转载 作者:行者123 更新时间:2023-12-02 10:45:04 27 4
gpt4 key购买 nike

我通过 SyncCredentials 登录 Realm 允许创建用户,代码如下:

SyncCredentials credentials = SyncCredentials.usernamePassword(username, password, true);
SyncUser.logInAsync(credentials, AUTH_URL, new SyncUser.Callback<SyncUser>() {
}

当我想使用以下代码删除 Realm 上的该用户后:

String id = SyncUser.current().getIdentity();
PermissionUser permissionUser = realm.where(PermissionUser.class).equalTo("id", id).findFirst();
if (permissionUser != null) {
permissionUser.getPrivateRole().removeMember(id);
permissionUser.getPrivateRole().deleteFromRealm();
if (permissionUser.getRoles() != null) {
permissionUser.getRoles().deleteAllFromRealm();
}
permissionUser.deleteFromRealm();
}

此代码运行成功,但我在 Realm Studio 上检查过,该用户仍然存在。请帮我解决这个问题,非常感谢。

最佳答案

所有数据更改都必须在事务中发生

来源:https://realm.io/docs/java/latest/

示例:

// obtain the results of a query
final RealmResults<Dog> results = realm.where(Dog.class).findAll();

realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
// remove single match
results.deleteFirstFromRealm();
results.deleteLastFromRealm();

// remove a single object
Dog dog = results.get(5);
dog.deleteFromRealm();

// Delete all matches
results.deleteAllFromRealm();
}
});

关于realm - 无法删除 Realm 用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53663369/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com