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 !
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?
It needs some tests, but I think there is certainly a way to get this column
somewhat related:
is there a way to make RelationId appear on the response?
Its not there, even when joining the actual relation as-well
@Bnaya as I said, you have to add @Column decorator on your attribute.
But it breaks the schema.
It makes schema sync never to get stable
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.
In my project I have to add the Column decorator to RelationIds for ManyToOne but not ManyToMany
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
Most helpful comment
I don't think that this is a
typeormissue.If I query the database using the typeorm
Repositorythe@RelationId()fields are always provided. It seems that the crud package filters those fields from the Repository response.