We have a use-case that requires us to use queryRunner.manager.query(); and not Repositories.
The table which we are querying has columns that are mapped to properties on our entity class, where some of the table column names differ from the property names used in our entity class.
For example,
@Entity('Car')
export class Car {
@Column('character varying', { name: 'make' }
type: string;
}
In this case, the entity "Car" has a column named "make" in the DB that is mapped to a property named "type", in the entity class.
Question: is there a way to instantiate an entity type from our model using the results from queryRunner.query()?
For example, something like:
const results = await dbConnection.queryRunner.manager.query(
`select * from cars where id = $1`,
[1]
);
// this is not valid TypeORM, but it conveys the idea
const car = new Car(results[0]);