Linking keywords with events
Now that we have shown the basics of creating commands and using the command bus in Nest.js CQRS, we need to tackle storing keywords that are associated with a blog entry. Keywords can be added when a blog entry is created and removed later. We could create a new entity for our keywords and have the entry entity maintain a one-to-many relationship with the keyword entity. This would, however, require our database lookups to pull in more data from more tables and the response sent back to the UI would become larger. Instead, let’s start off with just storing the keywords as a JSON string on the blog entry entity. To do this, we will need to update the blog entry entity and add a new field.
@
Table
(
tableOptions
)
export
class
Entry
extends
Model
<
Entry
>
{
@
Column
({
type
:DataType.TEXT
,
allowNull
:true
,
})
public
keywords
:string
;
}
The ORM definition for the new database column will depend on the ORM and database server...