title: grails joinTable with legacy database
body: <p>I have a one-to-many table mapping that I want to do with grails. I have a legacy database where I can't change the table structure. I have everything set up, but the only thing I can't figure out is how to get grails to notice the existing foreign keys instead of creating it's own column. I have something like this (simplified):</p>
  
  <pre><code>class Customer {
      String listID
      String name
      String address
      // more fields etc.
  
      static hasMany [notes : Note]
  
      static mapping = {
          table name:"customers"
          id name:"listID",generator:"assigned"
  
          // doesn't work, creates a foreign key column in customer_notes table
          // with key: customer_id. I want it to just use the existing column
          // CustomerListID, which has the correct foreign key
          notes joinTable:[name:"customer_notes",key:"CustomerListID"]            
      }
  }
  
  class Note {
      String noteID
      String customerListID
  
      static mapping = {
          table name:"customer_notes"
          id name:"NoteID",generator:"assigned"
       }
  }
  </code></pre>
  
  <p>As a side note, I see that joinTable in the grails document says "column" is the inverse column, and "key" is the foreign key. The examples in the docs aren't helpful. I have "Grails in Action" and it says it's going to provide a one-to-many example, then shows a many to many example, and either way it doesn't seem to be a complete example (half the model is missing)!</p>
  
  <p>Any ideas? I have this legacy database, and I'm going to use it read-only. I just want the O/R mapper to hook things together nicely.</p>