question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read property 'joinColumns' of undefined

See original GitHub issue

Issue 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:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

33reactions
pleerockcommented, Apr 25, 2018

@PavanBahuguni please read docs carefully about how to create bi-directional relations. THIS DOES NOT HAVE INVERSE SIDE:

@ManyToOne(type => Datasource)
    @JoinColumn({ name: 'id_datasource' })
    datasource: Datasource;

what it should be is:

@ManyToOne(type => Datasource, datasource => datasource. actions)
    @JoinColumn({ name: 'id_datasource' })
    datasource: Datasource;
5reactions
pleerockcommented, Apr 24, 2018

your datasource relation missing inverse side. You need to specify to point to actions

Read more comments on GitHub >

github_iconTop 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 >

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