Fix counter cache when association uses a class_name

The idea of this commits is from
bf28422cbda9068afb900020fa6911afd01963e1, which fixes this problem, but
only on AR 4.1+

[fixes #14369]