Fix counter cache to use relation name when possible.

[ fix #2970 ]