Skip to content

Commit

Permalink
This commit fixes a bug seen when using the tagged_with("something") …
Browse files Browse the repository at this point in the history
…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
Joe Goggins authored and tomeric committed Jun 21, 2010
1 parent 4671abe commit fae4236
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/acts_as_taggable_on/acts_as_taggable_on/core.rb
Expand Up @@ -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}" +
Expand All @@ -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}" +
Expand Down

0 comments on commit fae4236

Please sign in to comment.