Yii2 many to many relationship

I have a "article" table and "tag" table and they are joined by a "article_tag" table using many to many relationship.

Implementing in Yii2 is a bit difficult to me. Taking example from [here] i am able to save. However it is not very automated, as i have to loop through the tags selected to populate in article_tag. My question more about the "update" part. Updating the records will require me to consider one extra scenerio

if i remove one tag when updating, i have to verify the current data in the database against the newly submitted data and do delete first. I searched answers online to handle this scenerio, however there isnt much info online but simple insert etc.

Anyway Yii2 can handle this automatically?

Don’t bother. Unless you have a specific need to compare them, just delete all existing tags, save all tags selected.

You can look into link() to see if that works for you. Me, I just loop through. No biggie.