title: sequelize + sequelize-hierarchy: How enforce a unique organization name per level?
body: <p>I've an organizations' tree and want to ensure that there is only one organization (using its <code>name</code> and <code>parent_id</code>) at the same level in the tree, even at the root level.</p>
  
  <p>For instance:</p>
  
  <p><strong>valid trees:</strong></p>
  
  <p>/org1
     /org2</p>
  
  <pre><code>/org1/org2
       /org3
  </code></pre>
  
  <p><strong>invalid trees:</strong></p>
  
  <pre><code>/org1
  /org1
  
  
  /org1/org2
       /org2
  </code></pre>
  
  <p><strong>Model:</strong></p>
  
  <pre><code>var Organization = global.erp.orm.sequelize.define('Organization',
  lodash.extend({}, global.erp.orm.mixins.attributes, {
    name      : {
      type     : global.erp.orm.Sequelize.STRING,
      comment  : 'The organization short name (its common referred name).',
      allowNull: false
    }
  }), {
    comment  : 'An organization.',
    hierarchy: true
  });
  </code></pre>
  
  <p>I've tried the following but without any results:</p>
  
  <pre><code>{
    comment  : 'An organization.',
    hierarchy: true,
    indexes     : [
      {
        unique: true,
        fields: ['parent_id', 'name']
      }
    ],
  }
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I narrowed the issue to the case that when <code>parent_id</code> is NULL, so it seems that unique composite indexes don't work when one of the values is NULL.</p>
  
  <p>So, there is a solution to this?</p>
  
  <p>Thanks in advance.</p>