-
Notifications
You must be signed in to change notification settings - Fork 46
Description
Hi!
I cannot figure out how to correctly create data related to other data. The documentation provides an example with a blog post and comments. But it is not shown how to correctly create comments.
If I understand the documentation and the spec correctly, we only use the route POST /posts/1/relationships/comments to attach an existing comment to a blog post.
Apparently, to create a comment, we must use the standard route POST /comments. If so, then the information passed in the request should look something like this:
{
"data": {
"type": "comments",
"attributes": {
"comment": "My comment"
},
"relationships": {
"post": {
"data": {
"type": "posts",
"id": "1"
}
}
}
}
}Next, I probably have to write my processing in the controller, etc. Am I right? Or does the related data need to be created in some other way? For example, we can simply add the post_id field to the attributes of the new comment.