Relationships between data models
If you followed the chapter up to this point, you will have a way of saving new blog entries to your database through your API and then reading them back.
The next step is to create a second entity to handle comments in each blog entry and then create a relationship between entries and comments in such a way that one blog entry can have several comments that belong to it.
Let’s create the Comments
entity then.
src/comments/comment.entity.ts
import
{
Entity
,
Column
,
PrimaryGeneratedColumn
,
CreateDateColumn
,
UpdateDateColumn
,
VersionColumn
,
}
from
'typeorm'
;
@
Entity
()
export
class
Comment
{
@
PrimaryGeneratedColumn
(
'uuid'
)
id
:string
;
@
Column
(
'text'
)
body
:string
;
@
Column
(
'simple-json'
)
author
:
{
first_name
:string
;
last_name
:string
};
@
CreateDateColumn
()
created_at
:Date
;
@
UpdateDateColumn
()
modified_at
:Date
;
@
VersionColumn
()
revision
:number
;
}
You have probably noticed that...