January 2019
Intermediate to advanced
460 pages
10h 33m
English
A message is much like a post, except that it is only readable inside of a chat, and is not public to everyone.
Generate the model and migration file with the CLI, as follows:
sequelize model:generate --models-path src/server/models --migrations-path src/server/migrations --name Message --attributes text:string,userId:integer,chatId:integer
Add the missing references in the created migration file, as follows:
userId: { type: Sequelize.INTEGER, references: { model: 'Users', key: 'id' }, onDelete: 'SET NULL', onUpdate: 'cascade',},chatId: { type: Sequelize.INTEGER, references: { model: 'Chats', key: 'id' }, onDelete: 'cascade', onUpdate: 'cascade',},
Now, we can run the migrations again, in order to create the Messages table using ...
Read now
Unlock full access