Nested Controller parent param filter not working
See original GitHub issueWe are trying to have a nested controller for two objects: ProjectEntity |— InputEntity
When trying to send a GET request we get the following response:
column InputEntity.projectId_id._id does not exist
Here is my controller:
@Crud({
model: {
type: InputEntity
},
params: {
projectId: {
field: 'projectId',
type: 'uuid'
},
id: {
field: '_id',
type: 'uuid',
primary: true
}
}
})
@ApiTags('inputs')
@Controller('project/:projectId/inputs')
export class InputController {
The entity relation is defined as:
@ManyToOne(
type => ProjectEntity,
(project: ProjectEntity) => project.inputs,
{ onDelete: 'CASCADE' }
)
@ApiPropertyOptional()
projectId: ProjectEntity;
We had this code working a few weeks ago, but we tried multiple versions of this package, typeorm and postgres and can’t get it to work again.
After digging in into the code of NestJSX/curd we found that the resulting query has:
... WHERE ("InputEntity"."projectId_id._id" = $1)
And we try to execute it in a SQL editor and it is not a valid query.
Without the ._id
part the query works.
The strange field comes from entityColumnsHash
where in the initialization it thinks it is an embedded type (but it is stored as a simple ID string)
We will be thankful if this problem will be resolved as we can’t find a way to deploy our system in the present time.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:14
- Comments:5 (2 by maintainers)
Yes, while fixing filtering by relations and especially nested relations, I’ve changed a join relation internal mechanism, and actually I’m really surprised why this thing that you’ve described worked earlier because it looks wrong to me though - you’ve trying to filter by a relation name directly but not by either an entity column or a joint relation column name. Again, it’s very weird and not an intended behavior but rather a side effect of the bug we had earlier.
So, I see two possible solutions here. You can do one of these:
projectId_id
column to the entity:and change your param field name in the controller:
projectId
relation and filter by its_id
column:Also, let me notice something - usually, a relation name in your case would be called
project
but notprojectId
which confused me a little bit when I first saw this.Encountered the same issue - different routes worked and failed depending on the params field mapping. The workaround is to define 2 controllers for the same path with different routes options:
looks ugly but works. This is apparently a bug in the library.