Commit 29cd6905 by Rocky Duan

still working

parent 0ce290be
...@@ -29,7 +29,7 @@ class CommentThread ...@@ -29,7 +29,7 @@ class CommentThread
end end
def subscribers def subscribers
subscriptions.map{|s| User.find(s.subscriber_id)} subscriptions.map(&:subscriber)
end end
def to_hash(params={}) def to_hash(params={})
......
...@@ -20,7 +20,7 @@ class Commentable ...@@ -20,7 +20,7 @@ class Commentable
end end
def subscribers def subscribers
subscriptions.map{|s| User.find(s.subscriber_id)} subscriptions.map(&:subscriber)
end end
def to_hash(params={}) def to_hash(params={})
......
...@@ -2,9 +2,8 @@ class Subscription ...@@ -2,9 +2,8 @@ class Subscription
include Mongoid::Document include Mongoid::Document
include Mongoid::Timestamps include Mongoid::Timestamps
field :subscriber_id, type: String belongs_to :subscriber, class_name: "User", autosave: true
field :source_id, type: String belongs_to :source, polymorphic: true, autosave: true
field :source_type, type: String
index [[:subscriber_id, Mongo::ASCENDING], [:source_id, Mongo::ASCENDING], [:source_type, Mongo::ASCENDING]] index [[:subscriber_id, Mongo::ASCENDING], [:source_id, Mongo::ASCENDING], [:source_type, Mongo::ASCENDING]]
index [[:source_id, Mongo::ASCENDING], [:source_type, Mongo::ASCENDING]] index [[:source_id, Mongo::ASCENDING], [:source_type, Mongo::ASCENDING]]
......
...@@ -25,7 +25,7 @@ class User ...@@ -25,7 +25,7 @@ class User
end end
def followers def followers
follower_subscriptions.map{|s| User.find(s.subscriber_id)} follower_subscriptions.map(&:subscriber)
end end
def subscribe(source) def subscribe(source)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment