I've 3 tables.
Users (id, mail, username, etc..)
Practices (id, name)
UsersPractices (userId, practiceId)
The last one is the relational table which is n-n.
I'd like to update this one, depending on the user's will.
It means, that he could want to add, or remove some his practices.
What algorithm could i use to do this ?
Should it be better to let this job (if there is a way) to the database engine ? Or should i write my own algorithm to handle the data, then do my requests to the db ?
EDIT:
To be clear :
___________________________
| UserId | PracticeId |
|-----------|-------------|
| 12 | 21 |
|-----------|-------------|
| 12 | 18 |
|-----------|-------------|
Maybe, the user will try to change his practice from 21 to 15 but wants to keep the practice 18.
So, from the request, i'll get practices = array(15,18);
that means the users practice will look like :
___________________________
| UserId | PracticeId |
|-----------|-------------|
| 12 | 15 |
|-----------|-------------|
| 12 | 18 |
|-----------|-------------|
SO what is the best way to achieve this ?
Should i select & check each practice, and then, delete if needed ?
Delete them all, and add the news.