Merge pull request #160 from kytrinyx/tag-counts

Extract duplicated query from stats controller
This commit is contained in:
Matt Rogers 2013-03-01 18:52:52 -08:00
commit f375c06964
2 changed files with 29 additions and 24 deletions

View file

@ -0,0 +1,26 @@
module Stats
class UserTagsQuery
attr_reader :user
def initialize(user)
@user = user
end
def result
user.todos.find_by_sql([sql, user.id])
end
private
def sql
<<-SQL
SELECT tags.id as id
FROM tags, taggings, todos
WHERE tags.id = taggings.tag_id
AND taggings.taggable_id = todos.id
AND todos.user_id = ?
SQL
end
end
end