mapper icon indicating copy to clipboard operation
mapper copied to clipboard

option to disable auto flattening

Open whoruyh opened this issue 3 years ago • 4 comments

Is your feature request related to a problem? Please describe.

Source Class

  @AutoMap()
  @Column('varchar', { name: 'quest', length: 45 })
  quest: string;

  @AutoMap()
  @Column('varchar', { name: 'quest_title', length: 500 })
  questTitle: string;

  @AutoMap()
  @Column('varchar', { name: 'quest_sub_title', length: 500 })
  questSubTitle: string;

Dest Class

  @AutoMap()
  @Field()
  quest: string;

  @AutoMap()
  @Field()
  quest_title: string;

  @AutoMap()
  @Field()
  quest_sub_title: string;

Profile class

      namingConventions({
          source: new CamelCaseNamingConvention(),
          destination: new SnakeCaseNamingConvention(),
        }),

because of autoFlattening, quest_title and quest_sub_title behave differently than intended.

Describe the solution you'd like

I want to use namingConventions only. It would be nice to have options for autoFlattening.

Describe alternatives you've considered

No response

Additional context

No response

whoruyh avatar Apr 18 '22 02:04 whoruyh

any update on this? im having the same issue at the moment, its auto-flattening, and thus the fields in the dest are undefined because its assuming there is an object to map too instead of a 1:1 mapping of the same field and name.

the mapper should really check for the existence of an object that it can map to, and if not look for the associated property based on the naming convention.

Src { quantity: number, quantityType: string } Dest { Quantity: number, QuantityType: string }

using
source: PascalCaseNamingConvention(), destination: CamelCaseNamingConvention(),

QuantityType will be undefined due to auto flattening :(

mitch-tofi avatar Jun 08 '22 01:06 mitch-tofi

ideally it should do both? if theres an object that matches that convention, bind to it, but also if theres a property that matches, bind to that too? for now working around by explicitly using forMember for properties that have the issue

mitch-tofi avatar Jun 08 '22 02:06 mitch-tofi

This is harder that I thought it would. A lot more involved than anticipated. I have some time now after a month busy and dealing with personal stuffs. Will look into this deeper but I can't promise that it'd be a fast fix :(

nartc avatar Jul 01 '22 02:07 nartc

Hello, Any news on this ? Maybe an easy quick fix is to add a boolean property of autoflattening on the namingConventions() to avoid auto flattening all together, and maybe implement a "smarter" solution when you have the time ?

abouroubi avatar May 24 '23 16:05 abouroubi