From 83923dfc8421df2ccc77ee95527bd8e935220a79 Mon Sep 17 00:00:00 2001 From: Caio SBA Date: Fri, 23 Dec 2011 12:38:25 -0300 Subject: [PATCH] Comments for articles and activities --- vendor/plugins/action_tracker_has_comments/init.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vendor/plugins/action_tracker_has_comments/init.rb b/vendor/plugins/action_tracker_has_comments/init.rb index c716e69..3b5ac8d 100644 --- a/vendor/plugins/action_tracker_has_comments/init.rb +++ b/vendor/plugins/action_tracker_has_comments/init.rb @@ -2,6 +2,11 @@ ActionTracker::Record.module_eval do - has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc' + has_many :comments, :class_name => 'Comment', :dependent => :destroy, :finder_sql => 'SELECT * FROM comments WHERE #{conditions_for_comments} ORDER BY created_at ASC' + + def conditions_for_comments + type, id = (self.target_type == 'Article' ? ['Article', self.target_id] : [self.class.to_s, self.id]) + "source_type = '#{type}' AND source_id = '#{id}'" + end end -- libgit2 0.21.2