class CreateCustomerNewsgroups < ActiveRecord::Migration
  def change
    create_table :customer_newsgroups do |t|
      t.references :customer, index: true
      t.references :newsgroup, index: true

      t.timestamps null: false
    end
    add_foreign_key :customer_newsgroups, :customers
    add_foreign_key :customer_newsgroups, :newsgroups
    
    newsgroups = Newsgroup.where(:default_checked => true).all
    
    Customer.all.each do |customer|
      customer.newsgroups << newsgroups
    end
      
    
  end
end
