title: Help with HABTM :through
body: <p>My current HABTM implementation works so far with :has_and_belongs_to_many. Notification and Privacy both inherit from Preference. Preference is an STI. I want to try using :has_many, :through association instead.</p>
  
  <p><strong>Model files</strong></p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_and_belongs_to_many :preferences
  end
  
  class Preference &lt; ActiveRecord::Base
    has_and_belongs_to_many :users
  end
  
  class Notification &lt; Preference
  end
  
  class Privacy &lt; Preference
  end
  </code></pre>
  
  <p><strong>Migration files</strong></p>
  
  <pre><code>class UsersHaveAndBelongToManyPreferences &lt; ActiveRecord::Migration
    def self.up
      create_table :preferences_users, :id =&gt; false do |t|
        t.references :preference, :user
  
        t.timestamps
      end
    end
  
    def self.down
      drop_table :preferences_users
    end
  end
  
  class CreatePreferences &lt; ActiveRecord::Migration
    def self.up
      create_table :preferences do |t|
        t.string :title
        t.text :description
        t.string :type
  
        t.timestamps
      end
    end
  
    def self.down
      drop_table :preferences
    end
  end
  
  class DeviseCreateUsers &lt; ActiveRecord::Migration
    def self.up
      create_table(:users) do |t|
        t.string :name
        t.timestamps
      end
    end
  
    def self.down
      drop_table :users
    end
  end
  </code></pre>
  
  <p><strong>I tried the following</strong></p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_many :preferences, :through =&gt; :preferences_users
  end
  
  class Preference &lt; ActiveRecord::Base
    has_many :users, :through =&gt; :preferences_users
  end
  </code></pre>
  
  <p><strong>My form looks like</strong></p>
  
  <pre><code>  &lt;% Preference.where(:type =&gt; 'Notification').all.each do |notification| %&gt;
      &lt;li&gt;
        &lt;%= check_box_tag 'user[preference_ids][]', notification.id, @user.preference_ids.blank? ? false : @user.preferences.include?(notification) %&gt;
        &lt;%= label_tag notification.description %&gt;
      &lt;/li&gt;
    &lt;% end %&gt;
  </code></pre>
  
  <p><strong>I get</strong></p>
  
  <pre><code>Could not find the association :preferences_users in model User
  </code></pre>
  
  <p>What am I doing wrong? Is the problem in my form or in my association?</p>