Added tests to ensure that foreign keys get set before inverse relationships.