Search code examples
strapi

Is it possible to have repeatable objects in a object by using many to many relationship


My collections in strapi

  • Orders
  • Items

My goal

  • Collection Items

    • beer
    • water
    • sprite
  • example of a order

    • 3 beer
    • 2 water
    • 2 sprite

My situation

My solution was to use many to many relations between collections orders and items. So when i create a order like the example from above, i got the following result:

  • order
    • 1 beer
    • 1 water
    • 1 sprite

It seems that strapi can't handle repeatable (same id) items in a collection. Am i doing something wrong or is there just no way to make this kind of relations between collections.


Solution

  • In your case, I suggest you use a component (repeatable) to do that.

    In the Content Type Builder create a new component. With a number field and a relation field with your products.

    In your Order Content Type you add a component field, select the repeatable option and use the component you just created.

    With that, in your Orders, you will be able to add a new item, specify which item and the numbers of items (with the interfere field)