Skip to content

Instantly share code, notes, and snippets.

@tongueroo
Created November 25, 2008 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tongueroo/29023 to your computer and use it in GitHub Desktop.
Save tongueroo/29023 to your computer and use it in GitHub Desktop.
##
Article.find_by_sql("SELECT DISTINCT articles.* FROM articles INNER JOIN taggings ON taggings.taggable_id = articles.id WHERE taggings.tag_id = #{id} AND taggings.taggable_type = 'Article' AND articles.deleted_at IS NULL ORDER BY articles.id DESC LIMIT 5;")
##
Article.find_by_sql("SELECT DISTINCT articles.* FROM articles INNER JOIN taggings ON taggings.taggable_id = articles.id WHERE taggings.tag_id = #{id} AND taggings.taggable_type = 'Article' AND articles.deleted_at IS NULL ORDER BY articles.score DESC LIMIT 5;")
##
Article.find_by_sql(["SELECT DISTINCT articles.* FROM articles INNER JOIN taggings ON taggings.taggable_id = articles.id WHERE taggings.tag_id = #{id} AND taggings.taggable_type = 'Article' AND articles.deleted_at IS NULL AND articles.created_at > ? ORDER BY articles.comments_count DESC LIMIT 5;", 5.days.ago])
##
Article.find_by_sql(["SELECT DISTINCT articles.* FROM articles INNER JOIN taggings ON taggings.taggable_id = articles.id WHERE taggings.tag_id = #{id} AND taggings.taggable_type = 'Article' AND articles.deleted_at IS NULL AND articles.created_at > ? ORDER BY articles.hit_count DESC LIMIT 5;", 5.days.ago])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment