title: Habtm join tables for a model with a self join
body: <p>This follows on from my <a href="https://stackoverflow.com/questions/34697634/same-model-for-two-belongs-to-associations-migration/34705540#34705540">previous question</a> </p>
  
  <p>I have a user model with two self joins, seller and buyer.</p>
  
  <p>I have an categories model, a seller has_and_belongs_to_many categories, as does a buyer.
  How do I create the migration so I can do seller.categories and categories.buyers etc...</p>
  
  <p>I thought it would be something like I have below but it doesn't work...</p>
  
  <pre><code>def change
      create_table :categories_sellers do |t|
        t.references :category
        t.references :user
      end
      add_foreign_key :categories_sellers, :users, column: :trainer_id
      add_index :categories_users, [:category_id, :seller_id]
      add_index :categories_users, :seller_id
      end
    end
  </code></pre>