I'm using the ActsAsTaggableOn gem for Rails 3.0 and everything works fine.
Now I'm trying to speed up some queries selecting only some fields with ActiveRecord:
@items = Item.select("items.id, items.title").where("items.title IS NOT NULL)
@items.tag_counts
But I got this error back from MySQL:
> ActiveRecord::StatementInvalid开发者_如何学Go: Mysql::Error: Operand should contain 1 column(s): SELECT
SQL_NO_CACHE tags.*, COUNT(*) AS count FROM `tags` LEFT OUTER JOIN taggings ON tags.id =
taggings.tag_id AND taggings.context = 'tags' INNER JOIN items ON items.id =
taggings.taggable_id WHERE (taggings.taggable_type = 'Item') AND (taggings.taggable_id
IN(SELECT items.id, items.title, items.id FROM `items` WHERE (title IS NOT NULL)))
GROUP BY tags.id, tags.name HAVING COUNT(*) > 0
Instead if I regularly call tag_counts on the collection it works:
@items = Item.where("items.title IS NOT NULL)
@items.tag_counts
Any ideas for a simple workaround without editing the gem?
精彩评论