I have NoShow
abstract class which is parent for ActiveNoShow
and InactiveNoShow
.
And NoShow
have OneToMany relationship with NoShowPhoto
.
So NoShowPhoto is like the below:
@Entity()
export class NoShowPhoto extends Photo {
@ManyToOne(() => NoShow, (noShow) => noShow.photos)
noShow: NoShow;
}
In this case, NoShow table is created and NoShowPhoto's relationship is set with NoShow
.
InactiveNoShow.ts:
@Entity()
export class InactiveNoShow extends NoShow {
@Column()
reason: 0 | 1;
}
ActiveNoShow.ts:
@Entity()
export class ActiveNoShow extends NoShow {
// nothing
}
But what I want to create is ActiveNoshow
and InactiveNoShow
, not just NoShow
.
And the relation should be set
- between
ActiveNoShow
andNoShowPhoto
- between
InactiveNosHow
andNoShowPhoto
.
The red lines is what I would like to set relation and don't want to create NoShow
table.
Is there anyway to inherit OneToMany relation to ActiveNoShow
and InactiveNoShow
?
self-answer:
A column cannot be the foreign key for two tables at once.
Possible to do a MySQL foreign key to one of two possible tables?