[Question] How to represent nested One to Many Relationship using Repository pattern in GithubBrowserSample
See original GitHub issueFirst of all I want to say thanks for these samples which enlighten working with these new components significantly, looking at the code there is a lot to learn.
While playing with GithubBrowserSample project, I noticed that if my POJO have nested One to Many Relationships like this:-
public class User {
public int id;
public List<Pet> pets;
}
public class Pet {
public int id;
public String petName;
public List<Category> categories;
}
public class Category {
public int id;
public String categoryName;
}
Or if Pet class is @Embedded into the User class and has a list of Category like this
public class User {
public int id;
public Pet pet;
}
public class Pet {
public int id;
public String petName;
public List<Category> categories;
}
public class Category {
public int id;
public String categoryName;
}
It becomes really difficult to persisting and querying data having this kind of data structure with repository architecture demonstrated in GithubBrowserSample. I can use a @TypeConverter to convert the list of objects to string and vice versa, but would that be a recommended way? If not, how would you recommend it to be done? Can you provide some additional example or information about persisting this kind of data structure with room using the repository pattern similar to GithubBrowserSample.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:19
- Comments:13 (1 by maintainers)
Top GitHub Comments
I’d love to see a fully working sample, particularly one using
@Relation
instead of just some code snippets. That would simplify things tremendously.I wrote about simplifying one-to-many queries via
@Relation
, here - tip 6.