field linked with @relationId not found
See original GitHub issuehey,
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:
- Created 4 years ago
- Reactions:4
- Comments:8 (1 by maintainers)
Top 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 >
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 Free
Top 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
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
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.