title: CakePHP: creating / updating record (foreign key)
body: <p>I'm new to CakePHP and hope someone could help me with this one. I can't solve it on my own.</p>
  
  <p>I have a table 'games', with the following columns:<br/></p>
  
  <pre><code>- id
  - date
  </code></pre>
  
  <p>And a second table 'reports', with the following columns:<br/></p>
  
  <pre><code>- id
  - report
  - game_id (foreign key)
  </code></pre>
  
  <p>Game <code>hasOne</code> report and report <code>belongsTo</code> game.</p>
  
  <p>I'm trying to build a form that adds a report to an existing game. Whenever I add a new report, it creates a duplicate record. I have read that if Cake doesn't know the id, this will happen. And when I debug, the id-field is empty.</p>
  
  <p><strong>This is my aim:</strong> If there isn't a report for a game yet, an add-link will appear and if a report exists for a specific game, there's update link. Or there's respectively one link to a form that adds or edits report depending on if there is/isn't one. How this can be done?</p>
  
  <p>I have read that in <code>beforeSave()</code> -function, you could specify when create and when edit a record. I don't have an idea how this can be done.</p>
  
  <p>Currently my only solution is to validate the form and set game_id <code>isUnique</code> and to inform to the user that there's already a report with this game_id.</p>
  
  <p>Big thank you to anyone, who could help me with this!</p>