Refs #29. Made it work with nullable foreign keys.