I'm using TypeOrm in my project and I'm facing the problem that I cannot create the entity with lazy load association within the .create() method, however, I can do it outside the .create() by assigning the property manually, am I doing something wrong?
@Entity()
export class TemplateEntity extends BaseEntity {
@ManyToOne(
() => CategoryEntity,
(category) => category.templates,
)
category: Promise<CategoryEntity>;
}
@Entity()
export class CategoryEntity extends BaseEntity {
@Column()
name: string;
@OneToMany(() => TemplateEntity, (template) => template.category)
templates: Promise<TemplateEntity[]>;
}
const category1 = em.create(CategoryEntity, {
name: 'cate_1',
});
const template1 = em.create(TemplateEntity, {
name: 'temp_1',
data: 'some json here',
category: Promise.resolve(category1), //this is not working
});
console.log(await template1.category) //return a empty CategoryEntity{}
template1.category = Promise.resolve(category1);
console.log(await template1.category) //return category1