Closed michellelockett closed 6 years ago
One way to make this easier is to have a comment's subcomments returned in a 'children' array. For instance:
{ createdAt: "2018-03-16T02:46:29.000Z", id: 1, text: "What a great class. Continue your studies at Hack Reactor!", updatedAt: "2018-03-16T02:46:29.000Z", user: {...}, userId: 1, children: [ {...}, {...} ] }
The only thing new in the above code block is the 'children' array at the end. It is an array that holds, as objects, any comments that are nested under the current comment. The format (and schema) of each child comment would be identical to a 'parent' comment.
The latest PR implements some simple rendering of threaded comments. In line with discussions, we've kept the max depth of subcomments at 1. Will mark this as closed once everyone has had a chance to test and approve.
how to use self-referencing foreign keys in Sequelize:
https://stackoverflow.com/questions/24747652/sequelize-self-references-has-many-relation