Many to Many advice? please help

I have many-to-many relationship between User and Card.
How do I store User-specific details about each card the user has?
Example:
User: id: 1 {user: “John”, age: 24…}
Card: id: 1 {name: “Apple”, img: “URL”, color: “red”…}
UserCardDetails: id:1 { user: 1, card: 1, is_complete: true, is_favorite: false, progress: 5 …}

What is the best way to create this use-case in Strapi?
I have tried 3 ways:

  1. JSON attribute under User,
  2. Reusable Components under User,
  3. Relationship with UserCard ContentType

Which of these is the best approach? How do I set up the structure? Any ideas?

Attached are screenshots of the 3 aforementioned approaches.

  1. JSON

  1. Components

  1. Relationship

I believe the third one is the most flexible one, acting like a mapping table.

1 Like

Hey Thank you for answering! Do you think the JSON format would also work for production? My concern was that with relationship I might have to add ~ 300 rows / per user, and with json its just 1 field on 1 row. What do you think? THanks!!

You can handle millions of rows without any issue, don’t worry about this one. Mapping tables are quite performant.

The json would also work, but then you’ll have to handle yourself writing / update / deletion, + querying the 300 altogether everytime even if you need to get only one card, where with the mapping table you can maybe paginate if there is too much data

1 Like

I see! Thanks so much, that makes things a lot easier and clear now. Finally, my last concern with relationships would be - is it possible to set up somehow for when a new user logs in → to already have let’s say 10 cards as part of the tutorial (which would mean create 10 rows of relationships with user - card) is this hard or heavy performant or should be an easy task? TY!

Apologies for the late answer. This pretty straightforward to do, but it’s better to give this responsability to the backend. In your case settings the 10 cards in the user afterCreate lifecycle seems to be the best solution.