I am exploring different options for creating a service that retrieves relational data from the server. I have two potential approaches in mind, but I am having trouble deciding between them.
The first option involves returning the data as a multidimensional array of objects.
posts = [{id: 1, message: 'Sample 1', comments: [{id: 1, message: 'Sample comment 1', replies: [{id: 1, message: 'Sample reply 1'}]}]}]
Alternatively, the second option is to return a one-dimensional array for each object.
posts = [{id: 1, message: 'Sample ', comment_id: 1}]
comments = [{id: 1, message: 'Sample comment 1', reply_id: 1}]
replies = [{id: 1, message: 'Sample reply 1'}]
In both cases, I would compare the arrays by their foreign and primary keys.
I am unsure which approach is superior, or if there is another way to achieve this in Angular. My goal is to easily add, edit, and delete data on the server, as well as efficiently update or append new data to the object for viewing purposes.