I recently create some join tables I blissfully let a script run to populate them. The script ran for a few hours and it added about 20k entries which seemed reasonable. Only after it finished did I realize I had failed to create unique constraints on the join table so there were tons of duplicates. So here’s how you can remove duplicates from a join table in rails after the fact.
Let’s say you have two models, “model” and “other_model” and you want to remove duplicates from their join table. The easiest thing to do is:
Yup it’s that easy (:
You’re models probably look something like this: