'How to describe DTO with nested entity?

I am trying to save DTO with id of nested entity, but I am getting a problem: Argument of type 'CreateSpendingDto' is not assignable to parameter of type 'DeepPartial<Spending>[]'. How should I describe my DTO for pass it only with id?
My entity is:

@Entity('spending')
export class Spending {
  @Column()
  amount: number

  @ManyToOne(() => Category)
  @JoinColumn()
  category: Category

  @PrimaryGeneratedColumn()
  id: number
}

My DTO is:

export class CreateSpendingDto {
  readonly amount: number
  readonly category: number
}


Solution 1:[1]

I found answer, have to add a separate column with categoryId:

  @ManyToOne(() => Category)
  @JoinColumn({name: 'categoryId'})
  category: Category

  @Column()
  categoryId: number

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Valsin