title: Can't get "count" and "groupBy" with Grails DetachedCriteria
body: <p>I have a domain class that I use for querying .</p>
  
  <pre><code>TourIndex{
       Long tourId
       String country
       String location
       int availability
       // ... more fields
  }
  </code></pre>
  
  <p>We use a series if "dynamic" criteria builders for searching based on a series of configurations that basically results in performing:</p>
  
  <pre><code>def detachedCriteria = new DetachedCriteria(TourSearchIndex)
  
  detachedCriteria = detachedCriteria.build { eq('country','AR') }
  detachedCriteria = detachedCriteria.build { eq('location','salta') }
  </code></pre>
  
  <p>I want to reutilize this logic and get the available filters with their respective results in the form</p>
  
  <pre><code>[['location1', '3'], ['location2', '5']]
  </code></pre>
  
  <p>My wildest guess was:</p>
  
  <pre><code>detachedCriteria = detachedCriteria.build{
    projections{
      property('location')
      countDistinct('tourId')
    }
  }
  </code></pre>
  
  <p>But this results in a very obvious error</p>
  
  <pre><code>Caused by: org.h2.jdbc.JdbcSQLException: Column "THIS_.LOCATION" must be in the GROUP BY list; SQL statement:
  select this_.location as y0_, count(distinct this_.tour_id) as y1_ from tour_search_index this_ where this_.country=? [90016-173]
  </code></pre>
  
  <p>With createCriteria I have a way to get the count distinct, according to <a href="https://stackoverflow.com/questions/5977076/how-to-group-property-in-order-clause-using-grails-criteria">How to Group property in Order Clause using Grails Criteria</a> </p>
  
  <pre><code>def criteria = TourSearchIndex.createCriteria()
  
  def result = criteria.list {
    projections{
      groupProperty('location')
      countDistinct('id','idDistinct')
    }
    order('idDistinct','desc') 
  }
  </code></pre>
  
  <p>But I want to use the DetachedCriteria that already uses the rest of the application, is there a workaround for this? What I think is missing is the "groupProperty" in the DetachedProjection in DetachedCriteria's inner class.</p>
  
  <p>Thanks in advance.</p>