diff --git a/app/models/notification.rb b/app/models/notification.rb index 9f5bc4eff..dfe54a962 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -7,7 +7,7 @@ class Notification < ActiveRecord::Base include Diaspora::Socketable belongs_to :recipient, :class_name => 'User' - belongs_to :actor, :class_name => 'Person' + has_many :actors, :class_name => 'Person', :through => :notification_actors belongs_to :target, :polymorphic => true def self.for(recipient, opts={}) diff --git a/app/models/notification_actor.rb b/app/models/notification_actor.rb new file mode 100644 index 000000000..dc788cac3 --- /dev/null +++ b/app/models/notification_actor.rb @@ -0,0 +1,10 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +class NotificationActor < ActiveRecord::Base + + belongs_to :notification + belongs_to :person + +end diff --git a/app/models/person.rb b/app/models/person.rb index f502e478c..4f99c3c5d 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -29,6 +29,8 @@ class Person < ActiveRecord::Base belongs_to :owner, :class_name => 'User' + has_many :notifications, :through => :notification_actors + before_destroy :remove_all_traces before_validation :clean_url diff --git a/db/migrate/20110110023610_notification_multiple_people.rb b/db/migrate/20110110023610_notification_multiple_people.rb new file mode 100644 index 000000000..42f6c0382 --- /dev/null +++ b/db/migrate/20110110023610_notification_multiple_people.rb @@ -0,0 +1,25 @@ +class NotificationMultiplePeople < ActiveRecord::Migration + def self.up + create_table :notification_actors do |t| + t.integer :notifications_id + t.integer :person_id + t.timestamps + end + + add_index :notification_actors, :notifications_id + add_index :notification_actors, [:notifications_id, :person_id] , :unique => true + add_index :notification_actors, :person_id ## if i am not mistaken we don't need this one because we won't query person.notifications + + execute "INSERT INTO notification_actors (id, person_id) " + + " SELECT id , actor_id " + + " FROM notifications" + end + + def self.down + remove_index :notification_actors, :notifications_id + remove_index :notification_actors, [:notifications_id, :person_id] + remove_index :notification_actors, :person_id + + drop_table :notification_actors + end +end diff --git a/db/schema.rb b/db/schema.rb index b48fb9b95..59135130a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -293,6 +293,17 @@ ActiveRecord::Schema.define(:version => 20110127000953) do add_index "mongo_users", ["mongo_id"], :name => "index_mongo_users_on_mongo_id", :unique => true + create_table "notification_actors", :force => true do |t| + t.integer "notifications_id" + t.integer "person_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "notification_actors", ["notifications_id", "person_id"], :name => "index_notification_actors_on_notifications_id_and_person_id", :unique => true + add_index "notification_actors", ["notifications_id"], :name => "index_notification_actors_on_notifications_id" + add_index "notification_actors", ["person_id"], :name => "index_notification_actors_on_person_id" + create_table "notifications", :force => true do |t| t.string "target_type" t.integer "target_id"