class-validator
class-validator copied to clipboard
question: How can the parent properties be reached in the nested object?
I was trying to validate the nested object and faced an issue when it is not possible to reach the parent properties in the nested object:
Parent class:
export class ParentDto {
@Type(() => NestedDto)
@ValidateNested()
nestedProperty: NestedDto;
type: string;
}
Nested class:
export class NestedDto {
@ValidateIf((object) => object.type === 'some-type')
@IsString()
@IsNotEmpty()
value: string;
}
Is it possible to reach somehow "type" property from the ParentDto in the NestedDto? The only solution I get is to use @Transform to pass type in the NestedDto.
Is there any workaround found for this problem?
I need this as well. Trying out some custom validators.
I'm struggling to find similar feature.
Same here, is there any workaround or any actual way to do this?
Has anyone an answer for this? :(