Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #241 from alexbartlow/master

Fix long table aliases
  • Loading branch information...
commit 4690e041e59114ad1d42efaa463462140a703dba 2 parents 381348c + 62be0c6
@artemk artemk authored
Showing with 15 additions and 4 deletions.
  1. +3 −1 .gitignore
  2. +12 −3 lib/acts_as_taggable_on/acts_as_taggable_on/core.rb
View
4 .gitignore
@@ -5,4 +5,6 @@
.rvmrc
Gemfile.lock
spec/database.yml
-tmp
+tmp*.sw?
+*.sw?
+tmp
View
15 lib/acts_as_taggable_on/acts_as_taggable_on/core.rb
@@ -114,7 +114,9 @@ def tagged_with(tags, options = {})
# avoid ambiguous column name
taggings_context = context ? "_#{context}" : ''
- taggings_alias = "#{alias_base_name[0..4]}#{taggings_context[0..6]}_taggings_#{sha_prefix(tags.map(&:name).join('_'))}"
+ taggings_alias = adjust_taggings_alias(
+ "#{alias_base_name[0..4]}#{taggings_context[0..6]}_taggings_#{sha_prefix(tags.map(&:name).join('_'))}"
+ )
tagging_join = "JOIN #{ActsAsTaggableOn::Tagging.table_name} #{taggings_alias}" +
" ON #{taggings_alias}.taggable_id = #{table_name}.#{primary_key}" +
@@ -133,7 +135,7 @@ def tagged_with(tags, options = {})
tags.each do |tag|
- taggings_alias = "#{alias_base_name[0..11]}_taggings_#{sha_prefix(tag.name)}"
+ taggings_alias = adjust_taggings_alias("#{alias_base_name[0..11]}_taggings_#{sha_prefix(tag.name)}")
tagging_join = "JOIN #{ActsAsTaggableOn::Tagging.table_name} #{taggings_alias}" +
" ON #{taggings_alias}.taggable_id = #{table_name}.#{primary_key}" +
@@ -154,7 +156,7 @@ def tagged_with(tags, options = {})
end
end
- taggings_alias, tags_alias = "#{alias_base_name}_taggings_group", "#{alias_base_name}_tags_group"
+ taggings_alias, tags_alias = adjust_taggings_alias("#{alias_base_name}_taggings_group"), "#{alias_base_name}_tags_group"
if options.delete(:match_all)
joins << "LEFT OUTER JOIN #{ActsAsTaggableOn::Tagging.table_name} #{taggings_alias}" +
@@ -177,6 +179,13 @@ def tagged_with(tags, options = {})
def is_taggable?
true
end
+
+ def adjust_taggings_alias(taggings_alias)
+ if taggings_alias.size > 75
+ taggings_alias = 'taggings_alias_' + Digest::SHA1.hexdigest(taggings_alias)
+ end
+ taggings_alias
+ end
end
module InstanceMethods
Please sign in to comment.
Something went wrong with that request. Please try again.