Index: lib/tagging.rb =================================================================== --- lib/tagging.rb (.../vendor/acts_as_taggable/rev_6181) (revision 333) +++ lib/tagging.rb (.../trunk/sw/ObsidianPortal/vendor/plugins/acts_as_taggable) (revision 333) @@ -1,6 +1,7 @@ class Tagging < ActiveRecord::Base belongs_to :tag belongs_to :taggable, :polymorphic => true + belongs_to :user def self.tagged_class(taggable) ActiveRecord::Base.send(:class_name_of_active_record_descendant, taggable.class).to_s Index: lib/acts_as_taggable.rb =================================================================== --- lib/acts_as_taggable.rb (.../vendor/acts_as_taggable/rev_6181) (revision 333) +++ lib/acts_as_taggable.rb (.../trunk/sw/ObsidianPortal/vendor/plugins/acts_as_taggable) (revision 333) @@ -23,6 +23,19 @@ end module SingletonMethods + # Finds objects tagged with any of a list of tags, tagged by a specific user + def find_tagged_with_by_user(list, user) + find_by_sql([ + "SELECT #{table_name}.* FROM #{table_name}, tags, taggings " + + "WHERE #{table_name}.#{primary_key} = taggings.taggable_id " + + "AND taggings.user_id = ? " + + "AND taggings.taggable_type = ? " + + "AND taggings.tag_id = tags.id AND tags.name IN (?)", + user.id, acts_as_taggable_options[:taggable_type], list + ]) + end + + # Finds objects tagged with any of a list of tags. def find_tagged_with(list) find_by_sql([ "SELECT #{table_name}.* FROM #{table_name}, tags, taggings " + @@ -34,16 +47,18 @@ end end - module InstanceMethods - def tag_with(list) + module InstanceMethods + def tag_with(list, user) Tag.transaction do - taggings.destroy_all + Tagging.destroy_all(" taggable_id = #{self.id}" + + " and taggable_type = '#{acts_as_taggable_options[:taggable_type]}'" + + " and user_id = #{user.id}") Tag.parse(list).each do |name| if acts_as_taggable_options[:from] - send(acts_as_taggable_options[:from]).tags.find_or_create_by_name(name).on(self) + send(acts_as_taggable_options[:from]).tags.find_or_create_by_name(name).on(self, user) else - Tag.find_or_create_by_name(name).on(self) + Tag.find_or_create_by_name(name).on(self, user) end end end Index: lib/tag.rb =================================================================== --- lib/tag.rb (.../vendor/acts_as_taggable/rev_6181) (revision 333) +++ lib/tag.rb (.../trunk/sw/ObsidianPortal/vendor/plugins/acts_as_taggable) (revision 333) @@ -26,8 +26,8 @@ @tagged ||= taggings.collect { |tagging| tagging.taggable } end - def on(taggable) - taggings.create :taggable => taggable + def on(taggable, user) + taggings.create :taggable => taggable, :user_id => user.id end def ==(comparison_object)