If I have a base class called Animal
, with subclasses Dog
and Cat
.
export class Animal extends BaseEntity{
@PrimaryGeneratedColumn()
id:number;
}
@Entity()
export class Cat extends Animal{
...
}
@Entity()
export class Dog extends Animal{
...
}
Now, I want to establish a OneToOne
relationship between them and their respective owners.
@Entity
export class Owner extends BaseEntity{
....
@OneToOne()
pet:???
}
The class Owner
has an attribute pet
that can refer to either a cat or dog.
How can this be implemented using typeorm?
Or is there a better way to structure this relationship?