title: Mapping multiple domain objects to the same table using GORM DSL
body: <p>I'm creating a grails app over a legacy database.<br>
  There is a table out of which I would like to create several different domain objects (Type1, Type2 and Type3 in my example below).<br>
  The table is like this :</p>
  
  <pre><code>ID    TYPE    DESCRIPTION
  1     type1   description of a type1 object
  2     type1   description of another type1 object
  3     type2   description of a type2 object
  4     type3   description of a type3 object
  ...
  </code></pre>
  
  <p>So I would like to create 3 different domain classes, each containing a field named "description", and corresponding to a specific "type", because the rows represent different concepts.</p>
  
  <p>Is there any kind of constraint that allows me to filter the rows by type ?</p>
  
  <p>I mean, could I do something like :</p>
  
  <pre><code>class Type1 {
      String type
      String description
  
      static mapping = {
         table 'mytable'
      }
  
      static constraints = { type == 'type1' } // Is there anything like this ?
  
   }
  </code></pre>
  
  <p>Then I would expect Type1.list() to produce a query like :   </p>
  
  <pre><code>SELECT type, description 
  FROM mytable
  WHERE type = 'type1'
  </code></pre>
  
  <p>Update : </p>
  
  <p>Actually the <a href="http://grails.org/doc/latest/ref/Database%20Mapping/discriminator.html" rel="nofollow noreferrer">documentation</a> says that I can use a discriminator to achieve this.   </p>
  
  <p>However, I tried to set my class as follows :</p>
  
  <pre><code>class Type1 extends BaseType {
  
    static mapping = {
      discriminator column:'type', value: 'type1'
    }
  
  }
  </code></pre>
  
  <p>I activated hibernate SQL tracing, and instead of seeing </p>
  
  <pre><code>SELECT ... FROM mytable WHERE type = 'type1'
  </code></pre>
  
  <p>I see</p>
  
  <pre><code>SELECT ... FROM mytable WHERE class = 'type1'
  </code></pre>
  
  <p>It seems the discriminator is completely ignoring my custom column name :-(  </p>
  
  <p>I'm using Grails 1.2.1</p>