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

Error: Mapping is not found for class BaseEntity and class BaseVo #574

Open
4 of 9 tasks
zhanglp520 opened this issue Sep 14, 2023 · 1 comment
Open
4 of 9 tasks
Labels
bug Something isn't working

Comments

@zhanglp520
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the issue

Error: Mapping is not found for class BaseEntity {
static _OPENAPI_METADATA_FACTORY() {
return { id: { required: true, type: () => Number } };
}
} and class BaseVo {
static _OPENAPI_METADATA_FACTORY() {
return { id: { required: true, type: () => Number } };
}
}

Models/DTOs/VMs

=====================DO
@entity()
export class BaseEntity {
@PrimaryGeneratedColumn()
@AutoMap()
id: number;
}

@entity("dev_products")
export class ProductEntity extends BaseEntity {
@AutoMap()
@column({ type: "varchar", name: "product_id" })
productId: string;
}
======================VO

export class BaseVo {
@ApiPropertyOptional({ description: "主键" })
@AutoMap()
id: number;
}
export class ProductVo extends BaseVo {
@ApiProperty({ description: "产品编号" })
@AutoMap()
productId: string;
}

Mapping configuration

import { AutomapperProfile, InjectMapper } from "@automapper/nestjs";
import {
Mapper,
MappingConfiguration,
MappingProfile,
createMap,
extend,
forMember,
mapFrom,
} from "@automapper/core";
import { Injectable } from "@nestjs/common";
import { ProductEntity } from "../entities/product.entity";
import { ProductVo } from "../vo/product.vo";
import { DeviceEntity } from "../../device/entities/device.entity";
import { DeviceVo } from "../../device/vo/device.vo";
import { BaseVo } from "@/vos/base.dto";
import { BaseEntity } from "@/entities/base.entity";

@Injectable()
export class ProductMapperProfile extends AutomapperProfile {
constructor(@InjectMapper() mapper: Mapper) {
console.log("ProductMapperProfile-mapper", mapper);
super(mapper);
}

get profile(): MappingProfile {
return (mapper: Mapper) => {
createMap(
mapper,
ProductEntity,
ProductVo,
forMember(
(d) => {
console.log("zlp-d.devices", d.devices);
return d.devices;
},
mapFrom((s) => {
console.log("zlp-devices", s.devices);
const devices = mapper.mapArray(s.devices, DeviceEntity, DeviceVo);
return devices;
})
)
);
};
}

protected get mappingConfigurations(): MappingConfiguration[] {
return [extend(BaseEntity, BaseVo)];
}
}

Steps to reproduce

No response

Expected behavior

Mapping successful

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

@zhanglp520 zhanglp520 added the bug Something isn't working label Sep 14, 2023
@zhanglp520
Copy link
Author

The root cause is the mapping problem where attributes are arrays

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant