title: Rails has_many :through "ERROR - column products.category does not exist"
body: <p>Trying to resolve my issue, I've found a lot of common confusion surrounding <code>has_many :through</code> and <code>has_and_belongs_to_many</code> (which I'd like to avoid using). Reading through most of that on Stackoverflow makes me think I've set this up correctly:</p>
  
  <pre><code>class Product &lt; ActiveRecord::Base
    has_many :categorizations
    has_many :categories, :through =&gt; :categorizations
  end
  
  class Category &lt; ActiveRecord::Base
    has_many :categorizations
    has_many :products, :through =&gt; :categorizations
  end
  
  class Categorization &lt; ActiveRecord::Base
    belongs_to :product
    belongs_to :category
  end
  </code></pre>
  
  <p>And my migration. I've seen several ways to go about this, and this way seems valid:</p>
  
  <pre><code>class CreateCategorizations &lt; ActiveRecord::Migration
    def change
      create_table :categorizations, :id =&gt; false do |t|
        t.references :product
        t.references :category
      end
      add_index :categorizations, [:category_id, :product_id], :unique =&gt; true
    end
  end
  </code></pre>
  
  <p>And in my categories controller, I'm trying to create an ActiveRecord relation through this association:</p>
  
  <pre><code>class CategoriesController &lt; ApplicationController
    def show
      @category = Category.find(params[:id])
      @products = Product.where(:category =&gt; @category)
    end
  end
  </code></pre>
  
  <p>If I simply do <code>@category.products</code>, everything is fine, and I get an array/collection of a number of products included in that category. But I don't want an array. If I try to use <code>where</code> I get this error:</p>
  
  <pre><code>ActiveRecord::StatementInvalid - PG::UndefinedColumn: ERROR:  column products.category does not exist
  </code></pre>
  
  <p>Is there a more complex joins statement I should make to get an AR relation of products in a certain category? I'm sure it should work the way I'm attempting but obviously I've gone wrong somewhere.</p>
  
  <h1>Update</h1>
  
  <p>I've been able to create a relation with this code:</p>
  
  <pre><code>@products = Product.where(:id =&gt; @category.product_ids)
  </code></pre>
  
  <p>Is this the correct way to do this? I still feel like my "column does not exist error" indicates I've done something incorrectly elsewhere and need to identify it.</p>