Created
March 9, 2009 08:24
-
-
Save wuputah/76163 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def events_for_me limit = 10 | |
essay_ids = essays.all(:select => :id).map(&:id) | |
recording_ids = recordings.all(:select => :id).map(&:id) | |
essay_sql = "(resource_id IN (#{essay_ids.join}) AND resource_type= 'Essay')" | |
recording_sql = "(resource_id IN (#{recording_ids.join}) AND resource_type= 'Recording')" | |
my_comments = essays.ids.blank? ? [] : Comment.all(:conditions => "#{essay_sql} OR #{recording_sql}") | |
my_corrections = essays.ids.blank? ? [] : Correction.all(:conditions => "essay_id IN (#{essays_ids.join})") | |
(my_comments + my_corrections).sort_by{|x| x.created_at}.reverse[0...limit] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment