add tests + foreign-key fix (issue #38)