Just ignore fields in request when model is marked strict and do not throw error. #7206
-
|
I have created a User model with id. I am not allowing additional properties because I don't want to save extra data in the database. In lb4 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
@mevivek , you should remove the id before calling the Assuming you have the id as follows: export class User extends Entity {
@property({
type: 'number',
id: true,
generated: true,
})
id?: number;Then your controller should look like this: async create(
@requestBody({
content: {
'application/json': {
schema: getModelSchemaRef(User, {
title: 'NewUser',
}),
},
},
})
user: User,
): Promise<User> {
delete user.id;
return this.userRepository.create(user);
}Note that I removed the |
Beta Was this translation helpful? Give feedback.
@mevivek , you should remove the id before calling the
createrepository method.Assuming you have the id as follows:
Then your controller should look like this:
Note that I removed the
exclude: ['id'],. from the@requestBodydecorator and theOmit<User, 'id'>was replace…