title: Grails belongsTo multiple classes
body: <p>I have a domain class that can belong to one of several classes.  I'm seeing validation errors when I try to save.</p>
  
  <pre><code>class Teacher {
      Book book
  }
  
  class Student {
      Book book
  }
  
  // book can belong to either a student or a teacher
  class Book {
      static belongsTo = [student : Student, teacher : Teacher]
  }
  </code></pre>
  
  <p>The validation error suggests that a book must belong to BOTH a student and a teacher (neither can be null), but I want to model it so that it can belong to either.  How do I do this please?</p>
  
  <p>Please disregard the fact that for my example you could change it so that a Person owns a book and a Teacher and a Student are both types of Person - I want to know how how to create the correct belongsTo.</p>
  
  <p>Edit to explain reasoning behind requirement:</p>
  
  <p>There will be 3 tables created: Book, Student and Teacher.  I need to be able to create an index on the Book class that refers to Student and Teacher.  This is so the query that is "find all books that belong to Teacher A" can be made as fast as possible.</p>
  
  <p>If there was just a single belongsTo (example shown if for owner teacher)then this is done like this:</p>
  
  <p>static mapping = {
      teacher index: 'teacher_idx'
  }</p>