简体   繁体   中英

Exclude columns from clearing in realm database

Can i exclude two columns from clearing in Realm Database? when i use realm.clear(City.class) . For example i don't want to clear data on name and location columns When using clear method I want to save it from clearing

No, you cannot do that. First, Realm.clear() is renamed to Realm.delete() .

Basically the purpose of this API is to delete all the elements which are the type of given class. It is NOT set the default values to all the fields of those elements.

For your use case, you need to iterate and call set all values manually. Something like:

RealmResults<City> results = realm.where(City.class).findAll();

for (City city : results) {
    city.setName(null);
    city.setZipCode(0);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM