title: Category and Product mapping in activerecord
body: <p>With RoR ORM, how would you map this model.</p>
  
  <pre><code>Categories
  -id
  
  Products
  -id
  
  CategoriesProducts
  -category_id
  -product_id
  </code></pre>
  
  <p>So I want to perform queries like:</p>
  
  <pre><code>category.products.all
  product.category.id
  </code></pre>
  
  <p>In rails, how do you decide which side of the relationship will be used for adding products to a category?</p>
  
  <p>Will it be like:</p>
  
  <pre><code>category.add_product(product)
  </code></pre>
  
  <p>or</p>
  
  <pre><code>product.add_category(category)
  </code></pre>
  
  <p>And what if I wanted to fetch all categories with id 234,24,431,214 and products, is there a way I could do this w/o running into a n+1 query issue?</p>