Some work refactoring per-foreignkey templates. refs #474