Factor FK constraint logic out into a helper function