Fix setting foreign key on belongsTo

This should actually fix #353
Added test for issue #353
Merge pull request #359 from johanneslumpe/master

Fix setting foreign key on belongsTo