rocket_tag
rocket_tag copied to clipboard
Version 1.0.11 of squeel released on 09/03/2012 breaks rocket_tag
A TypeError (Cannot visit Arel::Nodes::TableAlias) is thrown when I use Model.popular_tags
This worked with squeel v 1.0.9
try this:
#config/initializers/taggable.rb
module RocketTag::Taggable::ClassMethods
def popular(options = {})
# Grab the current scope
s = select{"id"}
# Grab table name
t = self.to_s
q = RocketTag::Tag.joins{taggings}.
where{taggings.taggable_type==t}. # Apply taggable type
where{taggings.taggable_id.in(s)}. # Apply current scope
where(with_tag_context(options.delete(:on))). # Restrict by context
group_by_all_columns.
select{count(tags.id).as(tags_count)}.
select('tags.*').
order("tags_count desc")
# Isolate the aggregate query by wrapping it as
#
# select * from ( ..... ) tags
q = RocketTag::Tag.from(q.as(RocketTag::Tag.table_name))
# Restrict by minimum tag counts if required
min = options.delete :min
q = q.where{tags_count>=min} if min
# Return the relation
q
end
end
Then
Post.popular #=> [...]
What is the reason for the Squeel dependency? I look at it as more of a convenient interface on top of Arel, wouldn't it be better to interact directly with Arel or through Active Record to remove the extra dependency? Others can still add this Squeel to their project if they want to use it.
I'm having the error when I use SomeModel.tagged_with. locking squeel to 1.0.9 with bundler fixes it for the moment.