1

我正在为 Rails 3.0使用ActsAsTaggableOn gem,一切正常。

现在我正在尝试加快一些查询,只选择一些带有 ActiveRecord 的字段:

@items = Item.select("items.id, items.title").where("items.title IS NOT NULL)

@items.tag_counts

但是我从 MySQL 得到了这个错误:

> ActiveRecord::StatementInvalid: 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

相反,如果我经常在集合上调用 tag_counts 它可以工作:

@items = Item.where("items.title IS NOT NULL)

@items.tag_counts

无需编辑 gem 的简单解决方法有什么想法吗?

4

0 回答 0