Activerecord fix aggregate methods with select

Fixes issue #13648