Relations optimization

Hello everybody!

I’m trying to understand the better way to use a one to many and many to many relations.

In the doc i can read that the function to call is link() and unlink() to add or remove the data in the junction table.

BUT! how can i check if the data is yet here or not to not call link or call unlink if need?

I was thinking to read all the relations at the begin of the update query and then, for each of the value that i recive, check if the data is in the relation or not and then make the link, but i don’t know if there is a better way.

Even, wich is the better way to show to the admin a one to many and a many to many relations?

So, how do you make easy for the admin and user to choose, eg, all the categories for a single post?