Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desafio 07: GoFinances Web - Many-to-one / one-to-many relations #64

Open
ThyagoMC opened this issue Sep 26, 2020 · 0 comments
Open

Desafio 07: GoFinances Web - Many-to-one / one-to-many relations #64

ThyagoMC opened this issue Sep 26, 2020 · 0 comments

Comments

@ThyagoMC
Copy link

No trecho do README.md que fala sobre o eager loading tem a seguinte descrição:

Para isso, você pode utilizar a funcionalidade de eager loading do TypeORM, adicionando o seguinte na sua model de transactions:

 @ManyToOne(() => Category, category => category.transaction, { eager: true })
 @JoinColumn({ name: 'category_id' })
 category: Category;

Lembre também de fazer o mesmo na model de Category, mas referenciando a tabela de Transaction.

@OneToMany(() => Transaction, transaction => transaction.category)
transaction: Transaction;

Acredito que a ideia do trecho era apenas fazer uso do eager loading, nesse caso só precisaria usar o @ManyToOne, sem o @OneToMany.

Nesse cenário o código ficaria assim:
@ManyToOne(() => Category, { eager: true })
...

E o model Category não teria o trecho @OneToMany.

Agora caso ainda queira usar o @OneToMany ai teria que alterar o trecho do Category para receber um array de Transaction e não apenas uma transação e o restante do código permaneceria o mesmo informado.

Mais detalhes nesse link: https://orkhan.gitbook.io/typeorm/docs/many-to-one-one-to-many-relations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant