From aaa26a4c800d2abca188db61bf8d351c2128bfc2 Mon Sep 17 00:00:00 2001 From: Constantin Metz Date: Wed, 10 Mar 2021 18:27:42 +0100 Subject: [PATCH] added explanation on why id is omitted also added an explanation on why the orchestraId field must be defined in the interface, although we don't explicitly define it --- .../src/sequelize/models/instrument.model.ts | 6 ++++++ .../src/sequelize/models/orchestra.model.ts | 2 ++ express-main-example/src/sequelize/models/user.model.ts | 2 ++ 3 files changed, 10 insertions(+) diff --git a/express-main-example/src/sequelize/models/instrument.model.ts b/express-main-example/src/sequelize/models/instrument.model.ts index 29e7bf6..d654add 100644 --- a/express-main-example/src/sequelize/models/instrument.model.ts +++ b/express-main-example/src/sequelize/models/instrument.model.ts @@ -5,9 +5,15 @@ interface InstrumentAttributes { id: number; type: string; purchaseDate: Date; + + // We need to specify the 'orchestraId' field here, + // because it will automatically be defined later on + // when Sequelize applies the associations orchestraId: number; } +// we can omit the 'id' field, since we aren't required +// to set it manually when creating a new entry interface InstrumentCreationAttributes extends Omit {} diff --git a/express-main-example/src/sequelize/models/orchestra.model.ts b/express-main-example/src/sequelize/models/orchestra.model.ts index 9d41fe0..f3316e1 100644 --- a/express-main-example/src/sequelize/models/orchestra.model.ts +++ b/express-main-example/src/sequelize/models/orchestra.model.ts @@ -6,6 +6,8 @@ interface OrchestraAttributes { name: string; } +// we can omit the 'id' field, since we aren't required +// to set it manually when creating a new entry interface OrchestraCreationAttributes extends Omit {} export const Orchestra: ModelDefined< diff --git a/express-main-example/src/sequelize/models/user.model.ts b/express-main-example/src/sequelize/models/user.model.ts index 58d1409..7150222 100644 --- a/express-main-example/src/sequelize/models/user.model.ts +++ b/express-main-example/src/sequelize/models/user.model.ts @@ -6,6 +6,8 @@ interface UserAttributes { username: string; } +// we can omit the 'id' field, since we aren't required +// to set it manually when creating a new entry interface UserCreationAttributes extends Omit {} export const User: ModelDefined<