Good morning!
Hey everyone, I'm having an issue with my code that I need help solving. It involves a many-to-many relationship where users can subscribe to items.
user.entity.ts
@Entity("user")
export class UserEntity {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({
type: 'varchar',
length: 50,
unique: true,
})
username: string;
@Column('text')
password: string;
@Column('text')
role: string;
@OneToMany(type => SubscriptionEntity, subscriptionEntity => subscriptionEntity.user)
subscription: SubscriptionEntity[];
}
item.entity.ts
@Entity("item")
export class ItemEntity {
constructor() {}
@PrimaryGeneratedColumn() id: number;
@Column('text') name: string;
@Column('text') description: string;
@Column('decimal') price: number;
@Column('text') picture: string;
@OneToMany(type => SubscriptionEntity, subscriptionEntity => subscriptionEntity.item)
subscription: SubscriptionEntity[];
}
subscription.entity.ts
@Entity("subscription")
export class SubscriptionEntity {
@PrimaryColumn() userId: string;
@PrimaryColumn() itemId: number;
@ManyToOne(type => UserEntity, user => user.subscription)
@JoinColumn({name: "userId"})
user: UserEntity;
@ManyToOne(type => ItemEntity, item => item.subscription)
@JoinColumn({name: "itemId"})
item : ItemEntity;
}
I've noticed that the relationships and foreign keys are not appearing in my database:
desc subscription
+--------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+--------------+------+-----+---------+-------+
| userId | varchar(255) | NO | PRI | NULL | |
| itemId | int(11) | NO | PRI | NULL | |
+--------+--------------+------+-----+---------+-------+
I can't seem to find the issue despite following this link closely. Any suggestions?