What's the best way to create a "favorite" function?

I have a database of “assets” that users can favorite. What’s the best way to create this function? I have thought of 2 ways but both is not perfect:

First way is to create a new column in my “users” table called “favorites” with an array of asset ids that the user have favorited. I guess this could be confusing since everything is squished into an array.

Second way is to create a new database table called “favorites” and we table in any new favorites into this table. But the problem with this is what happens if someone decides to “unfavorite” something?

Ideally, I want to query the “assets” and be able to filter by the user’s “favorites” - “all assets”, “favorited assets”, etc. Which is better? Or is there another way?

1 Like

How many favorites might someone have? Are they all unique. Does date of like/order of likes matter?

I would lean towards a likes table but saving a list to the user isn’t crazy either depending on what you’re doing.

1 Like

Simply delete the record

1 Like

Same leaning here. It gives a bit more flexibility and, like you said @raelyn, things can start getting a bit confusing and messy when squished into an array.