I have a TypeORM entity called SuperResource
@Entity()
export class SuperResource extends BaseEntity {
@PrimaryGeneratedColumn()
id: number;
@OneToOne(() => Resource, {cascade: true, eager: true})
@JoinColumn()
resource: Resource
@Column({type: "enum", enum: ResourceTypes})
type: string
...
}
In addition to that, I have other entities that extend the Resource entity:
Job Entity
@Entity()
export class Job extends Resource {
@PrimaryGeneratedColumn()
id: number;
@Column()
jobId: number;
...
}
Table Entity
@Entity()
export class Table extends Resource {
@PrimaryGeneratedColumn()
id: number;
@Column()
description: string;
...
}
The Resource entity looks like this:
@Entity()
export abstract class Resource extends BaseEntity {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string
...
}
When I execute a query like
repository.findOne({ where: {id: parseInt(id)}})
, the object returned in the "resource" field only contains basic information.
Is there a way to retrieve full information based on the object's type?
I know using 2 queries can solve this issue, but I'm curious if there are alternate solutions. Thank you!