I have seen a few posts similar to this over the months, and just wanted to clarify the current state of things.
So say I have a blog with Post and Tag in a many to many, with a joining table, and I run this code
$tag1 = \Tag::findFirst('id=1');
$tag2 = \Tag::findFirst('id=2');
$tag3 = \Tag::findFirst('id=3');
// create a post
$post = new \Post();
$post->tags = array($tag1, $tag2);
$post->save();
// edit a post
$post = \Post::findFirst('id=1'); // the same post that was created earlier
$post->tags = array($tag1, $tag3);
$post->save();
What is the expected behaviour assuming I have everything set up correctly? I see there being 3 possiblities
- The post has tags 1, 2 & 3
- the post has tags 1 & 3
- the post has 2 of tag1 and 1 each of 2 & 3
Is one of these "right" or is it a config issue? If what is the syntax for choosing which one happens?