relationship references wrong table

Rebased version of #141 

fixes #68