Skip to content

Instantly share code, notes, and snippets.

@wuputah
Created March 9, 2009 08:24
Show Gist options
  • Save wuputah/76163 to your computer and use it in GitHub Desktop.
Save wuputah/76163 to your computer and use it in GitHub Desktop.
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