Permalink
Browse files

This commit fixes a bug seen when using the tagged_with("something") …

…method.

I have an ActiveRecord class defined like such:

	class Athlete < ActiveRecord::Base
		set_table_name "warehouse.ps_person"
		acts_as_taggable_on :tags
	end

Athlete.tagged_with("something") creates sql like this:

	SELECT `warehouse`.`ps_person`.* FROM `warehouse`.`ps_person`
	JOIN taggings warehouse.ps_person_taggings_something_932  ON warehouse.ps_person_taggings_something_932.taggable_id = warehouse.ps_person.emplid AND warehouse.ps_person_taggings_something_932.taggable_type = 'Athlete' AND warehouse.ps_person_taggings_something_932.tag_id = 2

This fix simply uses the undecorated_table_name instead of the table_name to define the basename of the alias
  • Loading branch information...
1 parent 4671abe commit fae4236357a93b206a289fd501b87cdfdb3bf5f7 @joegoggins joegoggins committed with tomeric Jun 16, 2010
Showing with 2 additions and 2 deletions.
  1. +2 −2 lib/acts_as_taggable_on/acts_as_taggable_on/core.rb
@@ -91,7 +91,7 @@ def tagged_with(tags, options = {})
safe_tag = tag.name.gsub(/[^a-zA-Z0-9]/, '')
prefix = "#{safe_tag}_#{rand(1024)}"
- taggings_alias = "#{table_name}_taggings_#{prefix}"
+ taggings_alias = "#{undecorated_table_name}_taggings_#{prefix}"
tagging_join = "JOIN #{ActsAsTaggableOn::Tagging.table_name} #{taggings_alias}" +
" ON #{taggings_alias}.taggable_id = #{table_name}.#{primary_key}" +
@@ -103,7 +103,7 @@ def tagged_with(tags, options = {})
end
end
- taggings_alias, tags_alias = "#{table_name}_taggings_group", "#{table_name}_tags_group"
+ taggings_alias, tags_alias = "#{undecorated_table_name}_taggings_group", "#{undecorated_table_name}_tags_group"
if options.delete(:match_all)
joins << "LEFT OUTER JOIN #{ActsAsTaggableOn::Tagging.table_name} #{taggings_alias}" +

0 comments on commit fae4236

Please sign in to comment.