I'm currently working on establishing the following relationships:
User is associated with one Account User is linked to one Application Application has multiple Members
The issue I'm encountering is that when the models are generated, the account table receives a foreign key of Application and the member's table doesn't get created at all.
Could someone please point out what I may be doing incorrectly? The code I am using is shown below:
//index.ts
const sequelize = new Sequelize(database, username, password, params);
sequelize.addModels([
Member,
Application,
Account,
User,
]);
return sequelize;
//Member.ts
import {
Table,
Column,
Model,
BelongsTo,
ForeignKey,
DataType,
} from "sequelize-typescript";
import { Application } from "./application";
@Table({ tableName: "Members" })
export class Member extends Model<Member> {
@ForeignKey(() => Application)
@Column({ type: DataType.INTEGER })
applicationId: number;
@BelongsTo(() => Application)
application: Application;
}
// Application.ts
import {
Table,
Column,
Model,
BelongsTo,
HasMany,
ForeignKey,
DataType,
} from "sequelize-typescript";
import { User } from "./user";
import { Member } from "./member";
@Table({ tableName: "Applications" })
export class Application extends Model<Application> {
....
}
//Account.ts
import {
Table,
Column,
Model,
BelongsTo,
ForeignKey,
DataType,
} from "sequelize-typescript";
import { User } from "./user";
@Table({ tableName: "ZohoCrms" })
export class ZohoCrm extends Model<ZohoCrm> {
....
}
//user.ts
export class User extend model<User> {
....
}