How to favourite objects for a user

0
Hi, I have a system set up where a user can favourite projects. This will also show a list of favourites or a full list. The problem that i am having is that because it is a one-many relationship one project can only be favourited by one user. Therefore if another user favourites that project then the first user looses the association.  I have no idea how to make a many-many relationship work. how can i get around this? Thanks    
asked
1 answers
1

Hello Ben,

If you wish to avoid many-to-many, I would go with some kind of ‘proxy’ entity that stores favourites for your users.

Make a “favourite” entity, and set up a “1 to many” association from users to favourites, and a “1 to many” from projects to favourites. This makes sure a single user can associate to multiple favourites, and every project can associate to multiple favourites. That would circumvent the issue where only 1 user or 1 project can be favourited.

Of course, I do urge you to make some deletion behaviour so Favourite entities get removed whenever a project or user gets deleted. This could bloat your system due to the multiplicative behaviour between amount of users and projects in an active system.

I hope you can work with this solution in your application.

answered