in the active record chapter on table joins, the following code is given:
def self.up create_table :products do |t| t.string :title # ... end create_table :categories do |t| t.string :name # ... end create_table :categories_products, :id => false do |t| t.integer :product_id t.integer :category_id end # Indexes are important for performance if join tables grow big add_index :categories_products, [:product_id, :category_id], :unique => true add_index :categories_products, :category_id, :unique => false end
Overall I understand the final goal here, I’m already familiar with table joins. But, I don’t think the book adequately explains the last two lines with ‘add_index’… I understand that the first statement informs us that the combination of :product_id and :category_id is unique, although I don’t quite understand why this is necessary since the id field in both the products and categories tables are going to be unique anyway… but why is :category_id set to :unique => false here??
can someone please illuminate me?