title: GORM One-to-Many relationship without foreign keys
body: <p>I've been trying for a while to understand how GORM works, and I think I've got it down.  However, I'm having a heck of a time getting my relationships correct.</p>
  
  <p>Here is my database schema setup (2 tables):</p>
  
  <p><strong>Table - Users</strong></p>
  
  <pre><code>userhash varchar(255)
  firstname varchar(255)
  lastname varchar(255)
  </code></pre>
  
  <p><strong>Table - Logs</strong></p>
  
  <pre><code>userhash varchar(255)
  accessdate date
  </code></pre>
  
  <p>There are no foreign key and primary key constraints defined in the tables.  However, in the users table the userhash will be unique.  I didn't design it this way, but I have to use it like this.</p>
  
  <p>Now for my Grails domain classes:</p>
  
  <p><strong>Class - Users</strong></p>
  
  <pre><code>class Users {
  
      String userhash;
      String firstname;
      String lastname;
  
      static hasMany = [logs: Logs]
  
  }
  </code></pre>
  
  <p><strong>Class - Logs</strong></p>
  
  <pre><code>class Logs {
  
      String userhash;
      Date accessdate;
  
      static belongsTo = Users;
  
  }
  </code></pre>
  
  <p>In my controller, I do the following:</p>
  
  <pre><code>def user = Users.findByUserhash("nraboy");
  println user.firstname;
  println user.logs;
  </code></pre>
  
  <p>It prints out the correct firstname, but when I try to display the logs, it is null or empty.  Am I requesting the data incorrectly for child tables or am I missing something somewhere in the domain class design?</p>
  
  <p>I've tried to do the following, but had now luck as well:</p>
  
  <p><strong>Class - Logs</strong></p>
  
  <pre><code>static mapping = {
      id generator: "assigned", name: "userhash", type: "string"
  }
  </code></pre>
  
  <p><strong>Class - Users</strong></p>
  
  <pre><code>static mapping = {
      userhash generator: "foreign"
  }
  </code></pre>
  
  <p>I figured the above would let me manually define the primary key and foreign key via code since it didn't exist int he tables.  No luck though.</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>Thanks,</p>