We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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 { static _OPENAPI_METADATA_FACTORY() { return { id: { required: true, type: () => Number } }; } } and class BaseVo { static _OPENAPI_METADATA_FACTORY() { return { id: { required: true, type: () => Number } }; } }
=====================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; }
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)]; } }
No response
Mapping successful
@automapper/core
@automapper/classes
@automapper/nestjs
@automapper/pojos
@automapper/mikro
@automapper/sequelize
8.7.7
The text was updated successfully, but these errors were encountered:
The root cause is the mapping problem where attributes are arrays
Sorry, something went wrong.
No branches or pull requests
Is there an existing issue for this?
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
@automapper/core
@automapper/classes
@automapper/nestjs
@automapper/pojos
@automapper/mikro
@automapper/sequelize
Other package and its version
No response
AutoMapper version
8.7.7
Additional context
No response
The text was updated successfully, but these errors were encountered: