A second model
Generating the comment model
Summary
In this lesson, we begin adding comments to our blogging application. Since a blog isn't complete without comments, we generate a new Comment model. This model includes two essential attributes:
commenter
– The name of the person commenting (required).body
– The content of the comment (required).
There’s also a third special attribute that we won’t cover in this lesson—it’s important enough to have its own dedicated lesson.
Refined Transcript
We've done a lot of work on our article model. Right now, we have a fully functional blogging application where users can add articles.
But what’s a blog without comments? Readers should be able to engage by leaving their thoughts. That’s what we’ll focus on in this chapter—adding comments to our blog.
To start, we need a Comment model to handle user comments on articles.
First, let's generate the model. In the terminal, we run:
sails generate model comment
Once that’s done, we’ll open the Comment model and define its attributes:
commenter
: The name of the person leaving the comment (required).body
: The actual comment text (required).
There’s also a third attribute, but we won’t cover it in this lesson. It’s a bit special and deserves its own dedicated lesson.
So if you’re ready, tune into the next lesson, where we’ll add this final attribute.
Full Course
USD