Hi,
I have some doubt regarding how i should create the models.
My app will sync some data from server. For example, i have lists of Account which joined several projects.
One project can be joined by several Accounts. At one time only one Account can active in the app.
Currently 'm using these models:
class Account extends RealmObject {
private long id;
private String name;
private RealmList<Project> projects;
}
class Project extends RealmObject {
private long Id;
private String name;
}
The behaviour are as follow:
1. Account1 is active after sync:
Account1 projects are ProjectA, ProjectB and ProjectD
2. Then activate Account2, after sync:
Account2 projects are ProjectA, ProjectB
3. Removed Account1 from ProjectA in the server.
4. Re-activate Account1, after sync:
Account1 projects are ProjectB and ProjectD
My sync process is simple, just delete all projects currently joined by Account1 then reinsert new data.
My question is, what would be the content of projects for Account2(before sync to server again)?
Will Account2 lost ProjectA.
I created the models as above because i want to cache the Project data.
I'm not sure it will work, and i guess i will lost ProjectA data for Account2 too.
Should i introduce another class? Something like:
class JoinedProject extends RealmObject {
private long accountId;
private Project project;
}
Then change the Account class into
class Account extends RealmObject {
private long id;
private String name;
private RealmList<JoinedProject> joinedProjects;
}
Thank you very much.