I have the following tables:
Announcements:
id | title | body
-----------------------
1 | test1 | test body1
2 | test2 | test body2
3 | test3 | test body3
Tags:
id | title | parent_id
-------------------------
1 | tag1 | (NULL)
2 | tag2 | 1
3 | tag3 | 2
And their pivot table:
Announcement_tag:
announcement_id | tag_id
1 | 1
2 | 2
3 | 3
I want the pivot table to look like this:
Announcement_tag:
announcement_id | tag_id
1 | 1
2 | 1
2 | 2
3 | 1
3 | 2
3 | 3
They decided to add auto insert for parent's tags for the new announcement system, but now the old announcements are combined with the new ones and some of them have parent's tags inserted and others don't. The problem is that they don't want to delete the old announcements. So now I need to find a way check if the announcement has tags with their parents or not and if it hasn't insert them into announcement_tag table.