MinFu MinFu - 14 days ago 5
Android Question

insert or update in realm cause duplication

I'm new to realm android and I'm try to perform

bgRealm.insertOrUpdate(write_feed);
operation but I found out that the record is duplicated. after that I tried to to set primary key to my model which I use url(string and not autoincrement) as my primar key it cause all the insertion failed. how to set a unique key to my url so that insertOr Update works

Answer

I solved my problem in order to make bgRealm.insertOrUpdate(write_feed); works, we need to set a primarykey in my case is the url the reason why is the insertion failed is because of I din't specific my primarkey value during create object.

write_feed = new FeedTable(); // Create a new object
write_feed.setFeed(feedJSON);
write_feed.setUpdatedtime(System.currentTimeMillis());
bgRealm.insertOrUpdate(write_feed);