credit Matthew Higgins for the integration of foreign keys. [ci skip]