Commit 83923dfc8421df2ccc77ee95527bd8e935220a79
Committed by
Daniela Feitosa
1 parent
28a5e5e7
Exists in
master
and in
29 other branches
Comments for articles and activities
Showing
1 changed file
with
6 additions
and
1 deletions
Show diff stats
vendor/plugins/action_tracker_has_comments/init.rb
... | ... | @@ -2,6 +2,11 @@ |
2 | 2 | |
3 | 3 | ActionTracker::Record.module_eval do |
4 | 4 | |
5 | - has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc' | |
5 | + has_many :comments, :class_name => 'Comment', :dependent => :destroy, :finder_sql => 'SELECT * FROM comments WHERE #{conditions_for_comments} ORDER BY created_at ASC' | |
6 | + | |
7 | + def conditions_for_comments | |
8 | + type, id = (self.target_type == 'Article' ? ['Article', self.target_id] : [self.class.to_s, self.id]) | |
9 | + "source_type = '#{type}' AND source_id = '#{id}'" | |
10 | + end | |
6 | 11 | |
7 | 12 | end | ... | ... |