Trouble with acts_as_taggable_on_steroids

The tag_counts instance method appears broken. I don’t have time to submit a patch right now, so I figured I’d write a quick post for others running into this issue. What I’m seeing is that if you try to access the tag_counts instance method (ie: @post.tag_counts), you’ll see a good times SQL exception much like the following:
(SQLite3::SQLException: near ")": syntax error: SELECT tags.id, tags.name, COUNT(*) AS count FROM "tags" INNER JOIN taggings ON tags.id = taggings.tag_id INNER JOIN posts ON posts.id = taggings.taggable_id WHERE (() AND taggings.taggable_type = 'Post') GROUP BY tags.id, tags.name HAVING COUNT(*) > 0):
, as the conditions builder doesn’t seem to take the model instance id into account when building the query.

The quick and dirty is to roll your own and add it to the model in question, and even this can probably be improved:
TAG_COUNT_SQL = "SELECT tags.id, tags.name, COUNT(*) AS count FROM tags INNER JOIN taggings ON tags.id = taggings.tag_id INNER JOIN posts ON posts.id = taggings.taggable_id WHERE ((posts.id = ?) AND taggings.taggable_type = 'Post') GROUP BY tags.id, tags.name HAVING COUNT(*) > 0 "

I’ve been running into enough plugin issues recently, that I’m definitely moving much closer to the always roll your own ideology as I use Rails more frequently…but, it does depend upon the use case the plugin is trying to solve. Some plugins are eminently malleable (as opposed to monkey patchable, and there is a difference), and thats a great feature.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

2 Responses to “Trouble with acts_as_taggable_on_steroids”

  1. Jonathan Viney

    This bug has been fixed. If you had emailed me about this bug I would have fixed it fairly quickly, like I did when someone emailed me today.

    Cheers.

  2. Matt Carlson

    Thanks. That probably would have been a much better approach than blogging about it and then forgetting about the issue!

Leave a Reply