Allow changing the AR database in beforeCount()

like it is possible in beforeFind() already.

fixes #3014