嘿,所以我已经多次把头靠在墙上来问这个问题了。我在任何地方都找不到解决方案,我很困惑。
由于某种原因,在以下代码中,
this.customerAddressRepository.create(data)
中的数据带有下划线并出现此错误:
No overload matches this call.
Overload 1 of 3, '(entityLikeArray: DeepPartial<CustomerAddress>[]): CustomerAddress[]', gave the following error.
Argument of type 'CreateCustomerAddressDto' is not assignable to parameter of type 'DeepPartial<CustomerAddress>[]'.
Type 'CreateCustomerAddressDto' is missing the following properties from type 'DeepPartial<CustomerAddress>[]': length, pop, push, concat, and 29 more.
Overload 2 of 3, '(entityLike: DeepPartial<CustomerAddress>): CustomerAddress', gave the following error.
Argument of type 'CreateCustomerAddressDto' is not assignable to parameter of type 'DeepPartial<CustomerAddress>'.ts(2769)
据我所知。 CustomerAddresses 中外键 ID 的实现类似于 Menus 中餐厅外键。谁能告诉我发生了什么事吗?我被困住了。
import { MenuItem } from 'src/menu-items/entities/menu-item.entity'
import { Restaurant } from 'src/restaurants/entities/restaurant.entity'
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne, OneToMany, JoinColumn } from 'typeorm'
@Entity('menus')
export class Menu {
@PrimaryGeneratedColumn('uuid')
id: string
@Column({ length: 255 })
name: string
@JoinColumn({ name: 'restaurant_id' })
@ManyToOne(() => Restaurant, restaurant => restaurant.menus)
restaurant: Restaurant
@OneToMany(() => MenuItem, menuItem => menuItem.menu, { cascade: true, eager: true })
menuItems: MenuItem[]
}
import { AddressDetail } from 'src/address-details/entities/address-detail.entity'
import { Customer } from 'src/customers/entities/customer.entity'
import { Entity, PrimaryGeneratedColumn, ManyToOne, JoinColumn } from 'typeorm'
@Entity('customer_addresses')
export class CustomerAddress {
@PrimaryGeneratedColumn('uuid')
id: string
@JoinColumn({ name: 'customer_id' })
@ManyToOne(() => Customer, customer => customer.addresses)
customer: Customer
@JoinColumn({ name: 'address_id' })
@ManyToOne(() => AddressDetail, { eager: true })
address: AddressDetail
}
import { Injectable } from '@nestjs/common'
import { CreateCustomerAddressDto } from './dto/create-customer-address.dto'
import { UpdateCustomerAddressDto } from './dto/update-customer-address.dto'
import { CustomerAddress } from './entities/customer-address.entity'
import { InjectRepository } from '@nestjs/typeorm'
import { Repository } from 'typeorm'
import { RpcException } from '@nestjs/microservices'
@Injectable()
export class CustomerAddressesService {
constructor(
@InjectRepository(CustomerAddress)
private readonly customerAddressRepository: Repository<CustomerAddress>,
) {}
async create(data: CreateCustomerAddressDto): Promise<CustomerAddress> {
const customerAddress = this.customerAddressRepository.create(data)
return this.customerAddressRepository.save(customerAddress)
}
}
import { Injectable, NotFoundException } from '@nestjs/common'
import { CreateMenuDto } from './dto/create-menu.dto'
import { UpdateMenuDto } from './dto/update-menu.dto'
import { Menu } from './entities/menu.entity'
import { InjectRepository } from '@nestjs/typeorm'
import { Repository } from 'typeorm'
import { RpcException } from '@nestjs/microservices'
@Injectable()
export class MenusService {
constructor(
@InjectRepository(Menu)
private readonly menuRepository: Repository<Menu>,
) {}
async create(data: CreateMenuDto): Promise<Menu> {
const menu = this.menuRepository.create(data)
return this.menuRepository.save(menu)
}
}
import { Module } from '@nestjs/common'
import { MenusService } from './menus.service'
import { MenusController } from './menus.controller'
import { TypeOrmModule } from '@nestjs/typeorm'
import { Menu } from './entities/menu.entity'
@Module({
imports: [TypeOrmModule.forFeature([Menu])],
controllers: [MenusController],
providers: [MenusService],
})
export class MenusModule {}
import { Module } from '@nestjs/common'
import { CustomerAddressesService } from './customer-addresses.service'
import { CustomerAddressesController } from './customer-addresses.controller'
import { CustomerAddress } from './entities/customer-address.entity'
import { TypeOrmModule } from '@nestjs/typeorm'
@Module({
imports: [TypeOrmModule.forFeature([CustomerAddress])],
controllers: [CustomerAddressesController],
providers: [CustomerAddressesService],
})
export class CustomerAddressesModule {}
我不知道该怎么办。我到处都看过了,但没发现任何异常。
你应该添加
TypeOrmModule.forFeature([Menu]),
在您的导入模块中