CRM-14500: refer to contact id foreign keys dynamically
Merge pull request #2998 from yashodha/CRM-14500

CRM-14500: refer to contact id foreign keys dynamically