title: Grails - check if item has parent
body: <p>I'm new to Grails, Groovy and GSP.</p>
  
  <p>I have a domain class "ProductCategory".</p>
  
  <pre><code>class ProductCategory {
  
      static constraints = {
      }
  
      static mapping = {
          table 'product_category';
          version false;
          cache usage: 'read-only';
          columns {
              parent column: 'parentid';
              procedure column: 'procid';
          }
  
      }
  
      static hasMany = [children:ProductCategory];
  
      ProductProcedure procedure;
      Integer lineorder;
      String name;
      ProductCategory parent;
      String templatelink;
      char offline;
  
      String toString() {
          return id + " (" + name + ")";
      }
  }
  </code></pre>
  
  <p>Each category CAN have a parent. I am using an existing database, and the table has a column 'parentid' to do that. When a category has no parent (root level), its parentid is 0.</p>
  
  <p>I have a GSP trying to show data about the parent if any.</p>
  
  <pre><code>&lt;g:if test="${category.parent}"&gt;
  hello
  &lt;/g:if&gt;
  </code></pre>
  
  <p>I was under the impression that this would test for existence.
  It works fine if the category DOES have a parent, but as soon as parentid=0, it blows up.</p>
  
  <pre><code>No row with the given identifier exists: [ProductCategory#0]
  </code></pre>
  
  <p>I tried to check for ==0, but it didn't work, I assume because 'parent' is supposed to be an object.</p>
  
  <p>So how can I make it so that it assumes that parentid=0 is the same as parent=null, or NO parent?</p>
  
  <p>Thanks</p>