diff --git a/lib/acts_as_taggable_on/taggable/related.rb b/lib/acts_as_taggable_on/taggable/related.rb index 8fb02d35a..7a9755108 100644 --- a/lib/acts_as_taggable_on/taggable/related.rb +++ b/lib/acts_as_taggable_on/taggable/related.rb @@ -49,7 +49,7 @@ def related_tags_for(context, klass, options = {}) private def exclude_self(klass, id) - "#{klass.table_name}.#{klass.primary_key} != #{id} AND" if [self.class.base_class, self.class].include? klass + "#{klass.arel_table[klass.primary_key].not_eq(id).to_sql} AND" if [self.class.base_class, self.class].include? klass end def group_columns(klass) diff --git a/spec/acts_as_taggable_on/related_spec.rb b/spec/acts_as_taggable_on/related_spec.rb index 0a3fc0332..71be8f627 100644 --- a/spec/acts_as_taggable_on/related_spec.rb +++ b/spec/acts_as_taggable_on/related_spec.rb @@ -33,6 +33,15 @@ expect(taggable1.find_related_tags).to_not include(taggable2) end + it 'should find related objects based on tag names on context - uuid primary key' do + taggable1 = TaggableModelWithUuidPrimaryKey.create!(name: 'Taggable 1',tag_list: 'one, two') + taggable2 = TaggableModelWithUuidPrimaryKey.create!(name: 'Taggable 2',tag_list: 'three, four') + taggable3 = TaggableModelWithUuidPrimaryKey.create!(name: 'Taggable 3',tag_list: 'one, four') + + expect(taggable1.find_related_tags).to include(taggable3) + expect(taggable1.find_related_tags).to_not include(taggable2) + end + it 'should find other related objects based on tag names on context' do taggable1 = TaggableModel.create!(name: 'Taggable 1',tag_list: 'one, two') taggable2 = OtherTaggableModel.create!(name: 'Taggable 2',tag_list: 'three, four') diff --git a/spec/internal/app/models/models.rb b/spec/internal/app/models/models.rb index 74927c980..35d858868 100644 --- a/spec/internal/app/models/models.rb +++ b/spec/internal/app/models/models.rb @@ -72,6 +72,15 @@ class NonStandardIdTaggableModel < ActiveRecord::Base has_many :untaggable_models end +class TaggableModelWithUuidPrimaryKey < ActiveRecord::Base + self.primary_key = :an_id + acts_as_taggable + acts_as_taggable_on :languages + acts_as_taggable_on :skills + acts_as_taggable_on :needs, :offerings + has_many :untaggable_models +end + class OrderedTaggableModel < ActiveRecord::Base acts_as_ordered_taggable acts_as_ordered_taggable_on :colours diff --git a/spec/internal/app/models/taggable_model_with_uuid_primary_key.rb b/spec/internal/app/models/taggable_model_with_uuid_primary_key.rb new file mode 100644 index 000000000..9a0941462 --- /dev/null +++ b/spec/internal/app/models/taggable_model_with_uuid_primary_key.rb @@ -0,0 +1,7 @@ +class TaggableModelWithUuidPrimaryKey < ActiveRecord::Base + acts_as_taggable + acts_as_taggable_on :languages + acts_as_taggable_on :skills + acts_as_taggable_on :needs, :offerings + has_many :untaggable_models +end diff --git a/spec/internal/db/schema.rb b/spec/internal/db/schema.rb index af9ba2ab4..556638871 100644 --- a/spec/internal/db/schema.rb +++ b/spec/internal/db/schema.rb @@ -1,4 +1,7 @@ ActiveRecord::Schema.define version: 0 do + enable_extension 'uuid-ossp' unless extension_enabled?('uuid-ossp') + enable_extension 'pgcrypto' if using_postgresql? && !extension_enabled?('pgcrypto') + create_table :tags, force: true do |t| t.string :name t.integer :taggings_count, default: 0 @@ -41,6 +44,11 @@ t.column :type, :string end + create_table :taggable_model_with_uuid_primary_keys, id: :uuid, force: true do |t| + t.column :name, :string + t.column :type, :string + end + create_table :untaggable_models, force: true do |t| t.column :taggable_model_id, :integer t.column :name, :string