Need a clever way to de-dupe data

​User 1 adds​ a Post for a new Item - first Item slug = item-a .

User 2 adds a Post for the same Item which creates a new Item in my database - second Item slug = item-a-1

Need to de-dupe so User 2’s Post points to Item where slug = item-a and then delete Item where slug = item-a-1

I need to: 1) Detect the dupe; 2) Connect User 2’s Post to the original item; 3) Delete the new (dupe) Item.

For detecting the dupe (step 1), I have a regex that will strip the last 2 chars of the Item slug.

I won’t bore you with the details, but rest assured there’s no easy way for me to prevent the creation of the duplicate Item so please don’t focus on that.

Thanks in advance!

Avoid creating it in the first place. I know … easier said … but many times … so valid

Also:
image
image