views:

21

answers:

0

Quick question:

>> Group.first.resources.joins(:tags).group("tags.id").select("tags.id, count(*)")
=> [#<Resource id: 1>, #<Resource id: 2>, #<Resource id: 3>, #<Resource id: 4>, #<Resource id: 5>]

This results in the following (correct) query:

"SELECT tags.id, count(*) FROM "resources" INNER JOIN "taggings" ON "resources"."id" = "taggings"."resource_id" INNER JOIN "tags" ON "tags"."id" = "taggings"."tag_id" INNER JOIN "group_resources" ON "resources".id = "group_resources".resource_id WHERE (("group_resources".group_id = 1)) GROUP BY tags.id"

I don't want the Resources, I want the damn Tags. Any clues?