class-validator icon indicating copy to clipboard operation
class-validator copied to clipboard

question: How can the parent properties be reached in the nested object?

Open eomelyusik opened this issue 3 years ago • 8 comments

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.

eomelyusik avatar Dec 28 '21 16:12 eomelyusik

Is there any workaround found for this problem?

adityajadhav95 avatar Jul 17 '22 11:07 adityajadhav95

I need this as well. Trying out some custom validators.

glothos avatar Sep 19 '22 15:09 glothos

I'm struggling to find similar feature.

IrfanHasib avatar Oct 12 '22 05:10 IrfanHasib

Same here, is there any workaround or any actual way to do this?

zhfahan77 avatar Feb 09 '23 04:02 zhfahan77

Has anyone an answer for this? :(

Iuriiiiiii avatar Jun 01 '23 14:06 Iuriiiiiii