1 class AddJoinTableBetweenUsersAndDiaryEntries < ActiveRecord::Migration
3 create_table :diary_entries_subscribers, :id => false do |t|
4 t.column :subscriber_id, :bigint, :null => false
5 t.column :diary_entry_id, :bigint, :null => false
8 add_foreign_key :diary_entries_subscribers, :users, :column => :subscriber_id, :name => "diary_entries_subscribers_subscriber_id_fkey"
9 add_foreign_key :diary_entries_subscribers, :diary_entries, :column => :diary_entry_id, :name => "diary_entries_subscribers_changeset_id_fkey"
11 add_index :diary_entries_subscribers, [:subscriber_id, :diary_entry_id], :unique => true, :name => "index_diary_subscribers_on_subscriber_id_and_diary_id"
12 add_index :diary_entries_subscribers, [:diary_entry_id]
16 DiaryEntry.find_each do |diary_entry|
17 diary_entry.subscribers << diary_entry.user unless diary_entry.subscribers.exists?(diary_entry.user.id)