question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] How to represent nested One to Many Relationship using Repository pattern in GithubBrowserSample

See original GitHub issue

First 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:closed
  • Created 6 years ago
  • Reactions:19
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

19reactions
dhaag23commented, Mar 29, 2018

I’d love to see a fully working sample, particularly one using @Relation instead of just some code snippets. That would simplify things tremendously.

15reactions
florina-muntenescucommented, Jan 9, 2018

I wrote about simplifying one-to-many queries via @Relation, here - tip 6.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Question] How to represent nested One to Many Relationship ...
[Question] How to represent nested One to Many Relationship using Repository pattern in GithubBrowserSample #92.
Read more >
Laravel Repository pattern and many to many relation
The "relationship" exists in the relational database. It only creeps into your objects if you're mixing database record / object like with AR....
Read more >
Using pattern "Repository" for table relations
If you want a one-to-many relationship from a repository, write a class that embodies that relationship, and return it from one of your ......
Read more >
Is the repository pattern useful with Entity Framework Core?
Performance – handling relationships: A repository normally returns a IEnumerable /IQueryable result of one type, for instance in the Microsoft ...
Read more >
4 Common Mistakes with the Repository Pattern
While reviewing various solutions, I've encountered a few common mistakes in the implementation of the repository pattern. One repository per ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found