TypeError: Cannot read property 'joinColumns' of undefined
See original GitHub issueIssue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[x] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
TypeORM version:
[ ] latest
[ ] @next
[x] 0.2.0
(or put your version here)
Steps to reproduce or a small repository showing the problem: Entities:
@Entity()
export class DatasourceAction {
@PrimaryGeneratedColumn()
id: string;
@Column({ name: 'name', type: 'text' })
name: string;
@Column({ name: 'action', type: 'text' })
action: string;
@Column({ name: 'id_datasource', type: 'varchar' })
datasourceId: string;
@ManyToOne(type => Datasource)
@JoinColumn({ name: 'id_datasource' })
datasource: Datasource;
}
@Entity('datasource')
export class Datasource {
@PrimaryColumn()
id: string;
@Column({ name: 'status', type: 'text', default: 'none' })
status: string;
@Column({ name: 'electorate_size', type: 'int4', default: 0 })
electorateSize: number;
@OneToMany(type => DatasourceAction, datasourceAction => datasourceAction.datasourceId, {
cascade: true
})
actions: Array<DatasourceAction>;
}
Query:
const dRepo = connection.getRepository(Datasource);
const datasource = await dRepo.save({
id: '11',
status: 'none',
electorateSize: 101,
actions: [
{
id: '5',
name: 'action one',
action: 'add',
datasourceId: '11',
}
]
});
If I do the dRepo.save for the first time, it inserts the entries into DB. But when I use the same object and call dRepo.save for the second time to update, it throws the below error.
Stack trace:
(node:94008) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'joinColumns' of undefined
at RelationIdLoader.<anonymous> (/Users/pavanbahuguni/practice/nest/typeorm/node-ts-graphql-boilerplate/src/query-builder/relation-id/RelationIdLoader.ts:62:70)
at step (/Users/pavanbahuguni/practice/nest/typeorm/node-ts-graphql-boilerplate/node_modules/typeorm/query-builder/relation-id/RelationIdLoader.js:32:23)
at Object.next (/Users/pavanbahuguni/practice/nest/typeorm/node-ts-graphql-boilerplate/node_modules/typeorm/query-builder/relation-id/RelationIdLoader.js:13:53)
at /Users/pavanbahuguni/practice/nest/typeorm/node-ts-graphql-boilerplate/node_modules/typeorm/query-builder/relation-id/RelationIdLoader.js:7:71
at new Promise (<anonymous>)
at __awaiter (/Users/pavanbahuguni/practice/nest/typeorm/node-ts-graphql-boilerplate/node_modules/typeorm/query-builder/relation-id/RelationIdLoader.js:3:12)
at /Users/pavanbahuguni/practice/nest/typeorm/node-ts-graphql-boilerplate/src/query-builder/relation-id/RelationIdLoader.ts:26:76
at Array.map (<anonymous>)
at RelationIdLoader.<anonymous> (/Users/pavanbahuguni/practice/nest/typeorm/node-ts-graphql-boilerplate/src/query-builder/relation-id/RelationIdLoader.ts:26:52)
at step (/Users/pavanbahuguni/practice/nest/typeorm/node-ts-graphql-boilerplate/node_modules/typeorm/query-builder/relation-id/RelationIdLoader.js:32:23)
(node:94008) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handledwith .catch(). (rejection id: 3)
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
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
When i try to leftJoin and load all products of a category I get error: TypeError: Cannot read properties of undefined (reading 'joinColumns')....
Read more >typeorm/typeorm - Gitter
TypeError : Cannot read property 'findOne' of undefined ... but if no existing entity is found in the database it returns undefined instead...
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 >setting up a one to many relationship for a self referencing table
TypeError : Cannot read property 'joinColumns' of undefined. Passing in a successorId of another existing project:.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@PavanBahuguni please read docs carefully about how to create bi-directional relations. THIS DOES NOT HAVE INVERSE SIDE:
what it should be is:
your
datasource
relation missing inverse side. You need to specify to point toactions