And still managing to do @OneToMany in another entity.
export class ProductsOfOrder {
@ManyToOne(() => Order, order => order.products)
order: Order
@ManyToOne(() => Product)
product: Product
@Column({type: 'integer'})
amount: number
}
In the case using the foreign key of order
@Entity()
export class Order {
@PrimaryGeneratedColumn('uuid')
id: string
@ManyToOne(() => User)
user: User
@OneToMany(() => ProductsOfOrder, productsOfOrder => productsOfOrder.order, {cascade: true})
products: ProductsOfOrder[]
}
Ciao, no you can't because its required for entities to have a primary column in terms of ORM because most of ORM operations are heavily rely on entity primary ids.