Regression tests and full fix for #118

  * Based on partial fix by @stupergenius
  * Handles nil case for hasOne associations