issue 1615: delete removed relations before adding

This can prevent duplicate key errors.
Merge pull request #3 from gumstix/issue1615

issue 1615: delete removed relations before adding