Hm, never seen that error before. What line throws the error? If it is the last line, sepparate it so you can see if it is the relationship saving that's the issue or the save command itself, such as:
If is the relationship make sure you have a join table defined properly, but I think if that were the issue you'd be getting a "could not relate objects" message.