Habtm relation size calculation fix

HABTM should fall back to using the normal CollectionAssociation's size calculation if the collection is not cached or loaded.

This addresses both #14913 and #14914 for master.

If I didn't break anything and if everyone's happy with the change, I will backport this to 3.2, 4.0 and 4.1.

cc @tenderlove @rafaelfranca @carlosantoniodasilva @senny

P.S. This fix was done independently to #14969.