Only nullify the keyId if we found the related model
added test the reproduces the original problem
Merge pull request #406 from idanz/patch-1

Only nullify the keyId if we found the related model