test case to fail without ensure_foreign_key_for
Ensure that a foreign key is always set.

cherry-pick 737f199a94ef75f294571b206ce77ff094731205
modify code to avoid using relations for Rails backwards compatibility
Merge pull request #311 from mingliangfeng/ensure-foreign-key

Merge "Ensure that a foreign key is always set"