I'm using TypeORM with Postgresql and having trouble creating entity file with nested scheme
The records I would like returned from my database should look like this:
[{
id: 1,
name: 'john'
preferences: {
colors: ['red', 'white', '#ff5d5d'],
cars: ['vw', 'bmw']
}
}]
Im having trouble with the preferences property.
this is what I tried:
@Entity()
export class Person {
@PrimaryGeneratedColumn()
id: string;
@Column()
name: string;
preferences: {
@OneToMany(() => Color, c => c)
colors: Color[]
@OneToMany(() => Car, c => c)
cars: Car[]
}
}
@Entity()
export class Color {
@PrimaryGeneratedColumn()
id: string;
@Column()
value: string;
}
@Entity()
export class Car {
@PrimaryGeneratedColumn()
id: string;
@Column()
value: string;
}
This does not compile because i cant put the OneToMany decorator in a nested property and
also I don't need id for the colors nor the cars.
I only use id because I need it mapped per person.