Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properties with similar names map to undefined #527

Open
4 of 9 tasks
nrgapple opened this issue Jan 11, 2023 · 2 comments
Open
4 of 9 tasks

Properties with similar names map to undefined #527

nrgapple opened this issue Jan 11, 2023 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed wontfix This will not be worked on

Comments

@nrgapple
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the issue

@AutoMap()
  inspection_order_status?: number;

  @AutoMap()
  inspection_order_status_id: number;
 @AutoMap()
  inspectionOrderStatus?: number;

  @AutoMap()
  inspectionOrderStatusId: number;

inspectionOrderStatusId will be undefined in these maps

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

Models/DTOs/VMs

No response

Mapping configuration

No response

Steps to reproduce

No response

Expected behavior

the values should map to their correct values

Screenshots

No response

Minimum reproduction code

No response

Package

  • I don't know.
  • @automapper/core
  • @automapper/classes
  • @automapper/nestjs
  • @automapper/pojos
  • @automapper/mikro
  • @automapper/sequelize
  • Other (see below)

Other package and its version

No response

AutoMapper version

8.7.7

Additional context

No response

@nrgapple nrgapple added the bug Something isn't working label Jan 11, 2023
@nartc
Copy link
Owner

nartc commented Mar 10, 2023

Thanks for reporting. The naming convention algorithm isn't smart enough to determine whether

  • inspection_order_status_id is inspection_order_status_id
  • inspection_order_status_id is inspection_order_status.id

when there is inspection_order_status in the object.

The workaround is to use forMember() on inspection_order_status_id. And please feel free to send a PR to fix the algorithm on this (packages/core/src/lib/utils/get-path.ts)

@nartc nartc closed this as not planned Won't fix, can't repro, duplicate, stale Mar 10, 2023
@nartc nartc reopened this Mar 10, 2023
@nartc nartc added help wanted Extra attention is needed wontfix This will not be worked on labels Mar 10, 2023
@vbrzezina
Copy link

Hello, as this was a blocker on my current project I decided to dig into it a little and found out the issue is in the flattening algorithm, where the shared suffix is being searched in source object, however, and that is my solution to the problem, it's not checked whether it's actually object and thus needs to be flattened. In the reference source object, primitive values are all undefined, but when there's nested objects, they're expanded as objects with their own properties. So this fix verifies, that the property to be flattened is an object.

I'm honestly wasn't sure if I should add it only at the two places I did or to just add it to the hasProperty function. I also didn't find any existing spec for getFlatteningPaths and as I'm not familiar with it in depth and don't know all the requirements, I'm not sure I'm up to writing all the other test cases..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants