Ensure HABTM relationships produce valid class names (Fixes #17119)