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.

Select @RelationId() - column not found

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 [ ] cockroachdb [ ] sqlite [ ] sqljs [ ] react-native [ ] expo

TypeORM version:

[x] latest [ ] @next [ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

@Entity({ schema: 'public' })
export class OAuthCode {

  @PrimaryGeneratedColumn()
  id: number;

  @ManyToOne(type => OAuthClient)
  @JoinColumn({ name: 'client_id', referencedColumnName: 'clientId' })
  client: OAuthClient;

  @RelationId((code: OAuthCode) => code.client)
  clientId: string;
}
@Entity({ schema: 'public' })
export class OAuthClient {

  @PrimaryGeneratedColumn()
  id: number;

  @Index({ unique: true })
  @Column()
  clientId: string;
}

If i try to select explicitly relation id field like :

const oauthCode: OAuthCode = await this.codeRepository.findOne({
      select: [
       'clientId',
      ]
      where: {
        code: requestCode,
      },
    });

I got

{
    "code": 503,
    "inner": {},
    "message": "clientId column was not found in the OAuthCode entity.",
    "name": "server_error",
    "status": 503,
    "statusCode": 503
}

Why it’s not possible to select @RelationId() like regular @Column() ?

Thanks !

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:9

github_iconTop GitHub Comments

1reaction
dzcpycommented, Dec 5, 2022

Not working, is it going to be fixed? Please…

1reaction
jiashengguocommented, May 31, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeORM One-To-One Relation: Entity column not found ...
My postgreSQL DB contains three Entities: @Entity() export class User { constructor(email: string, ...
Read more >
docs/decorator-reference.md | typeorm@v0.2.23-rc10
When set to false , the column data will not show with a standard query. By default column is select: true; default: string...
Read more >
PostgreSQL and typeorm - Relational data
Tip: Setting relationships with relation id. If you have created the join id column on your entities, you can use this to set...
Read more >
TypeORM - Relations
import {Entity, PrimaryGeneratedColumn, Column} from "typeorm"; @Entity() ... @JoinColumn() contain a “relation id” and foreign key to Customer table.
Read more >
Relations | TypeORM Docs
What are relations; Relation options; Cascades; @JoinColumn options ... nullable: boolean - Indicates whether this relation's column is nullable or not.
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