What is the correct way how to create relation in typeorm?

前端 未结 2 1547
小蘑菇
小蘑菇 2021-01-23 10:00

I have two entities:

@Entity({ name: \'provider\' })
export class ProviderEntity extends GenericEntity {

    @Column()
    name: string;

    @Column()
    descr         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-23 10:43

    Thanks to @alex-wayne who pointed out this question to me. For Reference, the approach which he proposed most likely originated from this github issue. More precisely this answer from pleerock, the core contributor.

    Moreover, I personally prefer the first approach. In practice, with the addition to using the create method:

    const content = 'mockContent';
    const providerId = '5be045b1-ef49-4818-b69f-a45c0b7e53';
    
    const provider = new Provider();
    provider.id = providerId;
           
    const item = this.itemRepository.craete({ content, provider })
    
    await this.repository.save(item);
    

提交回复
热议问题