title: Grails dynamic "inList"
body: <p>This is almost identical to this old question: <a href="https://stackoverflow.com/questions/24598532/dynamic-define-the-inlist-constraint-using-database-query">Dynamic define the inList constraint using database query</a> which was essentially unaddressed, perhaps there have been advances in the years since that was asked.</p>
  
  <p>I'd like to populate the <code>inList</code> parameter of a domain attribute with values from another domain.  Due to auto-generated views (scaffolding, filterpane), this needs to come from <code>inList</code> rather than a custom validator.</p>
  
  <pre><code>class MyDomain {
    String someValue
    static constraints = {
      someValue(nullable: true, maxSize: 50, inList: SomeOtherDomain.list()*.name)
    }
  }
  </code></pre>
  
  <p>This gives the following error on startup:</p>
  
  <p><code>Caused by: java.lang.IllegalStateException: Either class [thepackage.SomeOtherDomain] is not a domain class or GORM has not been initialized correctly or has already been shutdown. Ensure GORM is loaded and configured correctly before calling any methods on a GORM entity.</code></p>
  
  <p>I know, the "correct" way to handle this is to make <code>someValue</code> an instance of <code>SomeOtherDomain</code> instead of just storing the name, but that doesn't quite fit.  We want to be able to delete an instance of <code>SomeOtherDomain</code> without breaking the saved value of the owning domain...  the domain with the deleted value will be invalid going forward, and would have to be updated before saving, but archived/locked records will still exist and can be displayed.</p>