Cannot read property 'joinColumns' of undefined
See original GitHub issueIssue 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:
- Created 5 years ago
- Comments:11 (2 by maintainers)
Top Related StackOverflow Question
I observed that removing
eager: truestops the error in my case.Should be:
Where
$column_nameis the name of the column, that stores the foreign key of theCuota table(the column, that has a relation to the otherCuota tablefor examplecouta_id).That is because, you don’t relations to
couta.itemsbutcuota.id, becausecuota.itemsis not the actual nor it exists as a column inCuota table(cuota.itemsis 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 👍