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.

field linked with @relationId not found

See original GitHub issue

hey,

I have an error when I want to filter my request on a field with the decorator @RelationId: Invalid column name 'companyId'

I’m trying to filter on this field using the crud decorator:

@Crud(User, {
  params: {
    companyId: 'number'
  }
})

and here are the attributes of my model:

export class User {
  // ...
  @ManyToOne(type => Company, company => company.members, { nullable: true })
  @JoinColumn({ name: 'company_id' })
  company?: Company;

  @RelationId((user: User) => user.company)
  companyId?: number;
}

for now the only way to fix it is to add the @column decorator in addition to the @RelationId on companyId field, but there is certainly some impacts by doing this.

Thanks !

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
chriszrccommented, Oct 13, 2020

Would be great to have this resolved, I often have entities that are foreign keyed, but for many of the queries, don’t actually need the foreign table values. All I need is the column value that has the foreign key in the primary table. But I can’t get it currently without performing the join. @RelationId solves this problem in typeorm, but it’s not useable in with nestjs/crud, since adding the @Column would lead to an invalid schema creation if the class were used to recreate the table in the database, as @bintzandt mentioned

2reactions
bintzandtcommented, Aug 16, 2019

Hey, I have some doubts that this issue is directly related to nestjx/crud. It seems to be a typeorm issue. What do you think?

I don’t think that this is a typeorm issue.

If I query the database using the typeorm Repository the @RelationId() fields are always provided. It seems that the crud package filters those fields from the Repository response.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeORM insert with relationId - Stack Overflow
I use TypeORM, and simply I want to insert a row by using relationId . But it's not working as I expected. Here...
Read more >
Many-to-one / one-to-many relations - typeorm - GitBook
Where you set @ManyToOne - its related entity will have "relation id" and foreign key. This example will produce following tables:.
Read more >
"The image part with relationship rID8 was not found" error in ...
This occurs when there is a missing target in the XML document. The target field is set to "NULL." Resolution. To resolve this...
Read more >
REQUIRED_FIELD_MISSING:Required fields are missing ...
A required lookup field (parent object) is missing from the data template. Some implementations, such as Salesforce CPQ, expect certain child ...
Read more >
Relating Contacts from Invitees via Trigger
The EventRelation field IsParent defaults to FALSE, but updating it to TRUE makes this ... Are there other considerations I am missing?
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