1013837 - add missing associations

and add tests to ensure that all associations are there and configured
properly to avoid FK issues
Merge pull request #3294 from pitr-ch/bug/1013837

Add missing associations causing FK issues