Hi, I have a question about Many to Many as well as One to Many relationships in NgRx.
Would it be better to keep every entity separated and store them in their own State (for Example, User Model has many Note Models, and Note has one User), keep a separate User and Note state and couple them together in the selectors? (I assume so..)
Also, when calling the API I use, getting all Users doesn't return all their notes. I have to get the User by Id to get all the user along with all their notes, or call the notes endpoint explicitly.
Same principle applies with Many to Many relationships in this API.
What I am struggling with is, I don't really know how I can tie all entities with relationships together, the right way.
When I use a selector, it won't check if entity with id X actually exists in the current store.
I can't get 100 users with 4000 notes from the API for example. So I may have 10 users with 0 notes, but I want to do an API request to get the notes that belong to those users or the ones I want to interact with.
So if I have a list of 10 users displayed (serverside pagination), and I click on one to get all their notes, I would have to dispatch an action (getUserWithNotes or something?) where Users are stored in User state and Notes in Note state and then selectUserWithNotes where a Note(from note state) its userId is equal to the user I want to get(from user state).
And with many to many, how would I do that? For example, this time, user has many notes AND note has many users. (So there is a different object in between those 2, named UserNote for example)
In what state do I store the many to many relationship? Should it have its own state? and how would I make a selector for this?
Please let me know if I'm thinking wrong or if I'm doing it wrong and the way it should be done. Thanks!