title: Rails 4.1.x HABTM Undefined Method 'foreign_key'
body: <p>The following definition was working in Rails 4.0.x and lower:</p>
  
  <pre><code>module Gemgento
     class Product &lt; ActiveRecord::Base
        has_and_belongs_to_many :stores, -&gt; { distinct }, join_table: 'gemgento_stores_products', class_name: Gemgento::Store
     end
  end
  </code></pre>
  
  <p>However, after upgrading to Rails 4.1.x, I started to receive the following error whenever the <code>Gemgento::Product</code> class was initialized.</p>
  
  <pre><code>NoMethodError: undefined method `foreign_key' for #&lt;Class:0x007f870f18e668&gt;
  from /Users/Kevin/.rvm/gems/ruby-1.9.3-p429@sellect/gems/activerecord-4.1.4/lib/active_record/dynamic_matchers.rb:26:in `method_missing'
  from /Users/Kevin/.rvm/gems/ruby-1.9.3-p429@sellect/gems/activerecord-4.1.4/lib/active_record/associations/builder/has_and_belongs_to_many.rb:113:in `belongs_to_options'
  from /Users/Kevin/.rvm/gems/ruby-1.9.3-p429@sellect/gems/activerecord-4.1.4/lib/active_record/associations/builder/has_and_belongs_to_many.rb:82:in `through_model'
  from /Users/Kevin/.rvm/gems/ruby-1.9.3-p429@sellect/gems/activerecord-4.1.4/lib/active_record/associations.rb:1580:in `has_and_belongs_to_many'
  from /Users/Kevin/Sites/gemgento/app/models/gemgento/product.rb:21:in `&lt;class:Product&gt;'
  </code></pre>