Cannot read property 'joinColumns' of undefined

See original GitHub issue

Issue type:

[x] question [ ] bug report [ ] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [ ] mysql / mariadb [ ] oracle [ ] postgres [x] sqlite [ ] sqljs [ ] react-native [ ] expo

TypeORM version:

[ ] latest [ ] @next [x] 0.2.7

Steps to reproduce or a small repository showing the problem:

@Entity()
export class Cuota {
    @PrimaryGeneratedColumn()
    id:number;

    @ManyToOne(type => CuotaEstado, estado => estado.id)
    @JoinColumn()
    estado:CuotaEstado;

    @Column({ nullable: true })
    fecha_pago:Date;

    @OneToMany(type => ItemCuota, item => item.Cuota)
    items:ItemCuota[];
}

@Entity()
export class ItemCuota {
    @PrimaryGeneratedColumn()
    id:number;
    
    @Column()
    monto:number;
    
    @ManyToOne(type => Concepto, concepto => concepto.id)
    concepto:Concepto;

    @ManyToOne(type => Cuota, cuota => cuota.items)
    Cuota: number;
}

exports.get = async function(req:Request,res:Response){
    const userRepository = getManager().getRepository(Cuota);
    const cuota = await userRepository.findOne(1, { relations:["estado", "items"] });
    console.log(cuota);

    res.status(200).send(cuota);
}

Output TypeError: Cannot read property ‘joinColumns’ of undefined at C:.…\src\query-builder\SelectQueryBuilder.ts:1446:61 at Array.map (<anonymous>) at SelectQueryBuilder.createJoinExpression (C:.…\src\query-builder\SelectQueryBuilder.ts:1416:57) at SelectQueryBuilder.getQuery (C:.…\src\query-builder\SelectQueryBuilder.ts:51:21) at SelectQueryBuilder.QueryBuilder.getQueryAndParameters (C:.…\src\query-builder\QueryBuilder.ts:386:28) at SelectQueryBuilder.<anonymous> (C:.…\src\query-builder\SelectQueryBuilder.ts:1885:40) at step (C:.…\node_modules\typeorm\query-builder\SelectQueryBuilder.js:42:23) at Object.next (C:.…\node_modules\typeorm\query-builder\SelectQueryBuilder.js:23:53) at C:.…\node_modules\typeorm\query-builder\SelectQueryBuilder.js:17:71 at new Promise (<anonymous>)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
pratham2003commented, Apr 19, 2020

I observed that removing eager: true stops the error in my case.

2reactions
marmihacommented, Aug 5, 2018
@ManyToOne(type => Cuota, cuota => cuota.items)
    Cuota: number;

Should be:

@ManyToOne(type => Cuota, cuota => cuota.id)
@JoinColumn({name: "$column_name"})
    Cuota: number;

Where $column_name is the name of the column, that stores the foreign key of the Cuota table (the column, that has a relation to the other Cuota table for example couta_id).

That is because, you don’t relations to couta.items but cuota.id, because cuota.items is not the actual nor it exists as a column in Cuota table (cuota.items is a relation, for TypeOrm, but in items table you have to specify to which column in that table, the relation is connected to ).

Sorry, this isn’t my mother language. Hope i helped 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'joinColumns' of undefined · Issue #2016
I have ManyToOne defined in DatasourceAction , and OneToMany defined in Datasource. Both sides of the relation are defined. What is wrong in...
Read more >
Why joinColumns is undefined when trying to make a relation?
I'm getting TypeError: Cannot read property 'joinColumns' of undefined at <...>/src/persistence/SubjectOperationExecutor.ts:282:47 error ...
Read more >
typeerror: cannot read properties of undefined ... - You.com
How to fix 'Cannot read property 'joinColumns' of undefined' error in EntitySchema and Graphql. Asked Aug 30, 2019 • 2 votes 1 answer....
Read more >
typeorm/typeorm - Gitter
TypeError : Cannot read property 'findOne' of undefined ... project: Project; @OneToOne(type => User) @JoinColumn({ name: 'user_id' }) user: User;.
Read more >
typeorm cannot load relations : r/learnjavascript - Reddit
TypeError : Cannot read properties of undefined (reading 'joinColumns'). I also tried loading it with lines.itemRecord instead of setting ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found