title: Grails: Projection on many tables?
body: <p>I have some problems with projection in Grails. Could you please help me review them and suggest solutions for me?</p>
  
  <ol>
  <li><p>I want to query data on many tables which has many-to-one relationship and projection on some properties on both of them. For example:</p>
  
  <pre><code>class Person {
      int id
      String name
      String address
      static hasMany = [cars : Car]
  }
  
  class Car {
     int id
     String brand
     long price
     Person owner
     static belongsTo = [owner : Person]
  }
  </code></pre>
  
  <p>So, how can I use just one query withCriteria (apply projection) to get information of a specified car (include brand, price, and the owner name)? Is it possible to use:</p>
  
  <pre><code>Car.withCriteria {
       projections {
           property("brand")
           property("price")
           property("owner.name")
      }
      eq("id", carId)
  }
  </code></pre></li>
  <li><p>Can I use a projection to get information of one specified person along with name of all his cars? For example: [01, Perter, 01 Street A, [Mercedes, Toyota, Ducatti]]? </p></li>
  <li><p>A special situation: (with above Person class)<br>
  A person can join many Organization, and an Organization can have one "parent" Organizations (and vice versa, an Organization can have many other depend organizations). But there's a rule: a person just can join only one child organization of a given organization. So with a given organization O and a person P, what is the fastest way to get information of P along with the name of depended organization of O which has P as a member. I prefer to use Grails projection. </p>
  
  <p>Here's data model:  </p>
  
  <pre><code>class Person {
      int id
      String name
      String address
      static hasMany = [joinedOrgs : Organization] 
  }
  
  class Organization {
      int id
      String name
      Organization parentOrg
      static hasMany = [members : Person, childOrgs : Organization]
  }
  </code></pre></li>
  </ol>
  
  <p>I'm a newbie with Grails, and I'd like to understand GORM much more. Thank you so much for your help.</p>