fixed issue in active record query