mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-06 16:01:47 +01:00
Merge pull request #160 from kytrinyx/tag-counts
Extract duplicated query from stats controller
This commit is contained in:
commit
f375c06964
2 changed files with 29 additions and 24 deletions
26
app/models/stats/user_tags_query.rb
Normal file
26
app/models/stats/user_tags_query.rb
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue