wip
This commit is contained in:
parent
5940292840
commit
f48d7a0826
5 changed files with 49 additions and 1 deletions
|
|
@ -7,7 +7,7 @@ class Notification < ActiveRecord::Base
|
||||||
include Diaspora::Socketable
|
include Diaspora::Socketable
|
||||||
|
|
||||||
belongs_to :recipient, :class_name => 'User'
|
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
|
belongs_to :target, :polymorphic => true
|
||||||
|
|
||||||
def self.for(recipient, opts={})
|
def self.for(recipient, opts={})
|
||||||
|
|
|
||||||
10
app/models/notification_actor.rb
Normal file
10
app/models/notification_actor.rb
Normal file
|
|
@ -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
|
||||||
|
|
@ -29,6 +29,8 @@ class Person < ActiveRecord::Base
|
||||||
|
|
||||||
belongs_to :owner, :class_name => 'User'
|
belongs_to :owner, :class_name => 'User'
|
||||||
|
|
||||||
|
has_many :notifications, :through => :notification_actors
|
||||||
|
|
||||||
before_destroy :remove_all_traces
|
before_destroy :remove_all_traces
|
||||||
before_validation :clean_url
|
before_validation :clean_url
|
||||||
|
|
||||||
|
|
|
||||||
25
db/migrate/20110110023610_notification_multiple_people.rb
Normal file
25
db/migrate/20110110023610_notification_multiple_people.rb
Normal file
|
|
@ -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
|
||||||
11
db/schema.rb
11
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
|
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|
|
create_table "notifications", :force => true do |t|
|
||||||
t.string "target_type"
|
t.string "target_type"
|
||||||
t.integer "target_id"
|
t.integer "target_id"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue