title: In a join table, what's the best workaround for Rails' absence of a composite key?
body: <pre><code>create_table :categories_posts, :id =&gt; false do |t|
    t.column :category_id, :integer, :null =&gt; false
    t.column :post_id, :integer, :null =&gt; false
  end
  </code></pre>
  
  <p>I have a join table (as above) with columns that refer to a corresponding <em>categories</em> table and a <em>posts</em> table. I wanted to enforce a unique constraint on <strong>the composite key category_id, post_id</strong> in the <strong>categories_posts</strong> join table. But Rails does not support this (I believe). </p>
  
  <p>To avoid the potential for duplicate rows in my data having the same combination of category_id and post_id, <strong>what's the best workaround for the absence of a composite key in Rails</strong>? </p>
  
  <p>My assumptions here are:</p>
  
  <ol>
  <li>The default auto-number column
  (id:integer) would do nothing to
  protect my data in this situation.</li>
  <li>ActiveScaffold may provide a
  solution but I'm not sure if
  it's overkill to include it in my
  project simply for this single
  feature, especially if there is a
  more elegant answer.</li>
  </ol>