韋爾普,我能想到的唯一的選擇是
有2代表與結構基本相同,爲每一個對象的最後一個版本,第二個 - 所有先前版本。
關鍵的區別在於歷史記錄表沒有主鍵(或者是通過將原始主鍵與版本號拼接而構成的)。
public class Dog extends RealmObject {
@PrimaryKey
private String dogId;
@Index
private String dogName;
private int version;
}
public class DogHistory extends RealmObject {
private String dogId; // decide if primary key from dogId+version is needed
@Index
private String dogName;
private int version;
}
然後映射它們。
DogHistory dogHistory = new DogHistory();
dogHistory.setDogId(currentDog.getDogId());
dogHistory.setDogName(currentDog.getDogName());
dogHistory.setVersion(currentDog.getVersion());
realm.insert(dogHistory); //not "insertOrUpdate" if no PK field
棘手的事情是,你只能夠看到他們爲「同一個對象」,如果你通過接口暴露getter/setter方法。或者你映射回Dog
,但它會成爲一個非託管實例,然後。
聽起來像的東西,_might_使用[境界功能]是可能的(https://realm.io/docs/realm-object-server/#realm-functions)。你看過那裏嗎? –
@AviWarner這些是領域對象服務器功能,我們沒有使用它們。 – saabeilin