rocket_tag icon indicating copy to clipboard operation
rocket_tag copied to clipboard

Version 1.0.11 of squeel released on 09/03/2012 breaks rocket_tag

Open diangy opened this issue 12 years ago • 3 comments

A TypeError (Cannot visit Arel::Nodes::TableAlias) is thrown when I use Model.popular_tags

This worked with squeel v 1.0.9

diangy avatar Sep 05 '12 03:09 diangy

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 #=> [...]

fntz avatar Sep 06 '12 18:09 fntz

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.

ryanb avatar Sep 22 '12 19:09 ryanb

I'm having the error when I use SomeModel.tagged_with. locking squeel to 1.0.9 with bundler fixes it for the moment.

ethansr avatar Oct 03 '12 01:10 ethansr