title: Rails - How to use has_and_belongs_to_many association with Composite Primary Keys
body: <p>I am using Dr.Nic's Composite Primary Keys for rails (http://compositekeys.rubyforge.org/)</p>
  
  <p>In the examples he has has_many and belongs_to relation, but not has_and_belongs_to_many</p>
  
  <p>My association works good going from books to genres (books has a composite primery key of title and author), but genre to books tries to query the column book_id which doesn't exist in the join table, and raises an error.</p>
  
  <pre><code>class Book &lt; ActiveRecord::Base
    self.primary_keys = :title, :author
    has_and_belongs_to_many :genres, foreign_key: [:title, :author]
  end
  
  class Genre &lt; ActiveRecord::Base
    has_and_belongs_to_many :books, foreign_key: [:title, :author]
  end
  </code></pre>
  
  <p>Edit: I also got it to work using <code>:association_foreign_key</code> option on the Genre model</p>
  
  <pre><code>class Genre &lt; ActiveRecord::Base
    has_and_belongs_to_many :books, association_foreign_key: [:title, :author]
  end
  </code></pre>