title: Grails - How to implement a foreign key relationship not using an id column?
body: <p>Have been trying to look for an answer for hours, but have so far not managed to come up with an adequate solution, so I'm hoping someone here might have some more experience with Grails, and implementing custom relationships in it.</p>
  
  <p>My problem is that I have two classes:</p>
  
  <p>Company<br>
  OrderConfig</p>
  
  <p>OrderConfig contains two references to Company. 1 for a consignee, 1 for a shipper. I implemented the relationship (see below), and everything looks dandy, with my order_config table containing both a consignee_company_id column and a shipper_company_id column. </p>
  
  <p>However, I do not want or need a company_id column at all. I would prefer using the CompanyName as the identifying column. How can I prevent Grails from automatically adding the id column to the company table, and instead use the companyName column as the primary key, thus ensuring my order_config table will be generated containing the companyName and not the company_id?</p>
  
  <p>I tried embedding the company in the orderconfig class, and wrestled with all kinds of other options including the mappings, however I ran into trouble with each and every one of them.</p>
  
  <p>Thanks in advance!</p>
  
  <p>My code so far:</p>
  
  <pre><code>class OrderConfig {
   static hasMany = [consignee:Company, shipper:Company]
  
    String toString() {
      return "${consignee}"
   }
  
      static constraints = {
        consignee (blank:false, maxSize:10)
        shipper (blank:false, maxSize:10)
    }
  
    Company consignee
    Company shipper
  }
  
  
  
  
  class Company {
      String toString() {
      return "${companyName}"
   }
  
  static constraints = {
      companyName(blank:false, maxSize:10)
      companyAddress1(blank:false, maxSize:40)
      companyAddress2(blank:false, maxSize:40)
      companyAddress3(blank:false, maxSize:40)
      companyAddress4(blank:false, maxSize:40)
      companyZipCode(blank:false, maxSize:36)
      companyCountry(blank:false, maxSize:36)
  }
  
    String companyName
    String companyAddress1
    String companyAddress2
    String companyAddress3
    String companyAddress4
    String companyZipCode
    String companyCountry
  }
  </code></pre>