Adds onBeforeCount for Active Records, fixes #1353

Issue #1353