Serialize foreign key references to self

Fixes #24