class CreateAnnonceAccountNewsgroups < ActiveRecord::Migration
  def change
    create_table :annonce_account_newsgroups do |t|
      t.references :annonce_account, index: true
      t.references :newsgroup, index: true

      t.timestamps null: false
    end
    add_foreign_key :annonce_account_newsgroups, :annonce_accounts
    add_foreign_key :annonce_account_newsgroups, :newsgroups
    
    newsgroups = Newsgroup.where(:default_checked => true).all
    
    AnnonceAccount.all.each do |annonce_account|
      annonce_account.newsgroups << newsgroups
    end
      
    
  end
end
