Closed kevinsproles closed 4 years ago
After a few hours, found the solution. You need to specify the id field in the @Crud
params.id.field
like this, and btw it must match exactly case-sensitive to your entity id, in your entity file right below @PrimaryGeneratedColumn():
@Crud({
model: {
type: Categories,
},
params: {
id: {
field: 'categoryId',
type: 'number',
primary: true,
},
},
})
@Controller('categories')
export class CategoriesController {
constructor(public service: CategoriesService) {}
}
matching categories.entity.ts
:
@Entity({ name: 'categories' })
export class Categories {
@PrimaryGeneratedColumn()
categoryId: number;
...
Thank you!
using typeorm and
mssql
This happens on POST or PUT. It inserts / updates successfully, but the json response is:
And the console log gets:
have a very simple controller:
I've narrowed down this issue to only happen if the primary key column of the database table is not simply "id" but has some other name. In this case
categoryId
.