Skip to content

Commit

Permalink
added explanation on why id is omitted
Browse files Browse the repository at this point in the history
also added an explanation on why the orchestraId field must be defined in the interface, although we don't explicitly define it
  • Loading branch information
Keimeno committed Mar 10, 2021
1 parent cd6720c commit aaa26a4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions express-main-example/src/sequelize/models/instrument.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<InstrumentAttributes, "id"> {}

Expand Down
2 changes: 2 additions & 0 deletions express-main-example/src/sequelize/models/orchestra.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<OrchestraAttributes, "id"> {}

export const Orchestra: ModelDefined<
Expand Down
2 changes: 2 additions & 0 deletions express-main-example/src/sequelize/models/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserAttributes, "id"> {}

export const User: ModelDefined<
Expand Down

0 comments on commit aaa26a4

Please sign in to comment.