crud icon indicating copy to clipboard operation
crud copied to clipboard

Endpoints for unidirectional many to many without custom table?

Open felipecrs opened this issue 4 years ago • 1 comments

This library is awesome and incredibly extensive. However, I searched all over the places but could not find a similar situation.

Let's say I have:

// product.entity.ts

@Entity()
export class Product {
  @PrimaryGeneratedColumn()
  public id: number;

  @Column()
  public name!: string;
}

and

// shopping-list.entity.ts

@Entity()
export class ShoppingList {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ nullable: false })
  name: string;

  @ManyToMany(() => Product, { cascade: true })
  @JoinTable()
  products: Product[];
}

How am I supposed to expose CRUD endpoints for adding existing products to a shopping list without having to manually create a third entity ShoppingListHasProducts?

And then, probably put the CRUD controller at /shopping-lists/:shoppingListId/products.

The examples provided by the integration doesn't cover this case. There we have a custom relation entity (UserProject).

By the way, the real project is available at https://gitpod.io/#https://github.com/price-search/api

felipecrs avatar Jun 09 '20 03:06 felipecrs

Let me know if you find a solution for this. I'm trying to achieve the same behaviour without custom endpoints/resources.

glothos avatar Mar 17 '22 13:03 glothos