[SOLVED] It's possible, create a table without primary key in TypeOrm?

Issue

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[]
}

Solution

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.

Answered By – Giovanni Esposito

Answer Checked By – Mildred Charles (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *