0

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

  1. between ActiveNoShow and NoShowPhoto
  2. between InactiveNosHow and NoShowPhoto.

You can see as ERD below: enter image description here

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?

6991httam
  • 305
  • 4
  • 14

0 Answers0