I have two entities:
@Entity({ name: 'provider' })
export class ProviderEntity extends GenericEntity {
@Column()
name: string;
@Column()
description: string;
@OneToMany(() => ItemEntity, item => item.provider)
items: Promise<ItemEntity[]>;
}
@Entity({ name: 'item' })
export class ItemEntity extends GenericEntity {
@Column()
content: string;
@ManyToOne(() => ProviderEntity, provider => provider.items)
provider: Promise<ProviderEntity>;
}
Provider
object already exist in database and I would like to create item
with realtion to provider
.
My code is:
const content = 'mockContent';
const providerId = '5be045b1-ef49-4818-b69f-a45c0b7e53';
const item = new ItemEntity();
item.content = content;
item.provider = providerId; // ERROR
await this.repository.save(item);
return item;
The code it works, but I am getting an typescript error Type 'string' is not assignable to type 'Promise<ProviderEntity>'.
. What is the correct way how to insert this?
Generic entity class contains only id
@PrimaryGeneratedColumn('uuid')
id: string;