<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/acts_as_tagger.rb</filename>
    </added>
    <added>
      <filename>test/fixtures/user.rb</filename>
    </added>
    <added>
      <filename>test/fixtures/users.yml</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,13 +1,14 @@
 ActsAsTaggableRedux
 ===================
 
-Allows for tags to be added to multiple classes, and adds functionality to make tags easier to work with.  Note: The example and helper use RESTful routes, which require using EDGE rails.  Please install that first if you want to use this functionality.
-
+Allows for user owned tags to be added to multiple classes, and makes tags easier to work with.
 
 
 Prerequisites
 =============
 
+Install Edge Rails before you get started so you get RESTful routing.
+
 ActsAsTaggableRedux depends on database tables to store tagging information.  Create the migration for these tables with this command:
   
   rake acts_as_taggable:db:create
@@ -16,6 +17,9 @@ Then run the migration to create the tables with this command:
   
   rake db:migrate
   
+Also you will need to add this to your user model:
+  acts_as_tagger
+  
 OPTIONAL: To pretty up tag clouds and lists you can generate an example stylesheet with this command:
 
   rake acts_as_taggable:stylesheet:create
@@ -47,6 +51,9 @@ app/views/items/new.erb
     
   &lt;% end -%&gt;
   
+if you want users to own taggings add this into the form
+  &lt;%= f.hidden_field :user_id, :value =&gt; user.id -%&gt;
+  
 app/views/items/show.erb
   Item tagged with: 
   &lt;% item.tags.each do |tag| -%&gt;</diff>
      <filename>README</filename>
    </modified>
    <modified>
      <diff>@@ -10,13 +10,16 @@ class AddActsAsTaggableTables &lt; ActiveRecord::Migration
     create_table :taggings do |t| 
       t.column :tag_id, :integer 
       t.column :taggable_id, :integer 
-      t.column :taggable_type, :string 
+      t.column :taggable_type, :string
+      t.column :user_id, :integer
     end     
 	
-    # Find objects for a tag 
+    # Find objects for a tag
     add_index :taggings, [:tag_id, :taggable_type] 
+    add_index :taggings, [:user_id, :tag_id, :taggable_type]
     # Find tags for an object 
-    add_index :taggings, [:taggable_id, :taggable_type, :tag_id] 
+    add_index :taggings, [:taggable_id, :taggable_type] 
+    add_index :taggings, [:user_id, :taggable_id, :taggable_type]
   end 
    
   def self.down </diff>
      <filename>generators/acts_as_taggable_tables/templates/migration.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,7 @@
 require 'acts_as_taggable'
+require 'acts_as_tagger'
 ActiveRecord::Base.send(:include, ActiveRecord::Acts::Taggable)
+ActiveRecord::Base.send(:include, ActiveRecord::Acts::Tagger)
 ActionView::Base.send(:include, ActsAsTaggableHelper)
 
 require File.dirname(__FILE__) + '/lib/tagging'</diff>
      <filename>init.rb</filename>
    </modified>
    <modified>
      <diff>@@ -12,8 +12,8 @@ module ActiveRecord
           
           after_save :update_tags
           
+          extend ActiveRecord::Acts::Taggable::SingletonMethods          
           include ActiveRecord::Acts::Taggable::InstanceMethods
-          extend ActiveRecord::Acts::Taggable::SingletonMethods
         end
       end
       
@@ -23,7 +23,7 @@ module ActiveRecord
         # Options:
         #   :match - Match taggables matching :all or :any of the tags, defaults to :any
         def find_tagged_with(tags, options = {})
-          options.assert_valid_keys([:match])
+          options.assert_valid_keys([:match, :user])
           
           tags = Tag.parse(tags)
           return [] if tags.empty?
@@ -39,6 +39,28 @@ module ActiveRecord
               :group  =&gt;  group
             })
         end
+        
+        # Pass a tag string, returns taggables that match the tag string for a particular user.
+        # 
+        # Options:
+        #   :match - Match taggables matching :all or :any of the tags, defaults to :any
+        def find_tagged_with_by_user(tags, user, options = {})
+          options.assert_valid_keys([:match])
+          
+          tags = Tag.parse(tags)
+          return [] if tags.empty?
+          
+          group = &quot;#{table_name}_taggings.taggable_id HAVING COUNT(#{table_name}_taggings.taggable_id) = #{tags.size}&quot; if options[:match] == :all
+          
+          find(:all, 
+            { 
+              :select =&gt;  &quot;DISTINCT #{table_name}.*&quot;,
+              :joins  =&gt;  &quot;LEFT OUTER JOIN taggings #{table_name}_taggings ON #{table_name}_taggings.taggable_id = #{table_name}.#{primary_key} AND #{table_name}_taggings.taggable_type = '#{name}' &quot; +
+                          &quot;LEFT OUTER JOIN tags #{table_name}_tags ON #{table_name}_tags.id = #{table_name}_taggings.tag_id&quot;,
+              :conditions =&gt; sanitize_sql([&quot;#{table_name}_tags.name IN (?) AND #{table_name}_taggings.user_id = ?&quot;, tags, user]),
+              :group  =&gt;  group
+            })
+        end
       end
       
       module InstanceMethods
@@ -48,6 +70,10 @@ module ActiveRecord
           end
         end
         
+        def user_id=(new_user_id)
+          @new_user = User.find(new_user_id)
+        end
+        
         def tag_list
           tags.collect { |tag| tag.name.include?(&quot; &quot;) ? %(&quot;#{tag.name}&quot;) : tag.name }.join(&quot; &quot;)
         end
@@ -58,7 +84,7 @@ module ActiveRecord
               taggings.destroy_all
             
               Tag.parse(@new_tag_list).each do |name|
-                Tag.find_or_create_by_name(name).tag(self)
+                Tag.find_or_create_by_name(name).tag(self, @new_user)
               end
 
               tags.reset</diff>
      <filename>lib/acts_as_taggable.rb</filename>
    </modified>
    <modified>
      <diff>@@ -28,9 +28,9 @@ class Tag &lt; ActiveRecord::Base
     return tag_names
   end
   
-  # Tag a taggable with this tag
-  def tag(taggable)
-    taggings.create :taggable =&gt; taggable
+  # Tag a taggable with this tag, optionally add user to add owner to tagging
+  def tag(taggable, user = nil)
+    taggings.create :taggable =&gt; taggable, :user =&gt; user
     taggings.reset
     @tagged = nil
   end</diff>
      <filename>lib/tag.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,5 @@
 class Tagging &lt; ActiveRecord::Base
   belongs_to :tag, :counter_cache =&gt; true
   belongs_to :taggable, :polymorphic =&gt; true
+  belongs_to :user
 end
\ No newline at end of file</diff>
      <filename>lib/tagging.rb</filename>
    </modified>
    <modified>
      <diff>@@ -25,6 +25,7 @@ class ActsAsTaggableTest &lt; Test::Unit::TestCase
   end
   
   def test_update_tags
+    current_user = users(:monki)
     assert_equal things(:bear).tag_list, &quot;animal \&quot;not green\&quot;&quot;
     things(:bear).tag_list = 'animal &quot;not green&quot; favorite'
     assert_equal things(:bear).tag_list, &quot;animal \&quot;not green\&quot;&quot;</diff>
      <filename>test/acts_as_taggable_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -10,11 +10,18 @@ ActiveRecord::Schema.define :version =&gt; 0 do
     t.column :tag_id, :integer
     t.column :taggable_id, :integer
     t.column :taggable_type, :string
+    t.column :user_id, :integer
   end
   add_index :taggings, [:tag_id, :taggable_type] 
-  add_index :taggings, [:taggable_id, :taggable_type, :tag_id]
+  add_index :taggings, [:user_id, :tag_id, :taggable_type]
+  add_index :taggings, [:taggable_id, :taggable_type] 
+  add_index :taggings, [:user_id, :taggable_id, :taggable_type]
   
   create_table :things, :force =&gt; true do |t|
     t.column :name, :string
   end
+  
+  create_table :users, :force =&gt; true do |t|
+    t.column :username, :string
+  end
 end
\ No newline at end of file</diff>
      <filename>test/schema.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,8 +1,6 @@
 require File.dirname(__FILE__) + &quot;/test_helper&quot;
 
 class TagTest &lt; Test::Unit::TestCase
-  fixtures :taggings, :tags, :things
-
   def test_taggings
     assert_equal [taggings(:bear_animal), taggings(:frog_animal)], tags(:animal).taggings
     assert_not_equal [taggings(:cactus_plant), taggings(:orange_plant)], tags(:animal).taggings</diff>
      <filename>test/tag_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,8 +1,6 @@
 require File.dirname(__FILE__) + &quot;/test_helper&quot;
 
 class TaggingTest &lt; Test::Unit::TestCase
-  fixtures :taggings, :tags, :things
-  
   def test_taggable
     assert_equal things(:bear), taggings(:bear_animal).taggable
     assert_not_equal things(:frog), taggings(:bear_animal).taggable    </diff>
      <filename>test/tagging_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>53476837d913f2f4344d2d7a2c82ba1fb909cfd0</id>
    </parent>
  </parents>
  <author>
    <name>monki@geemus.com</name>
    <email>monki@geemus.com@89c3609e-b12b-0410-95a9-e792c7af2e16</email>
  </author>
  <url>http://github.com/geemus/acts_as_taggable_redux/commit/bd348cbda136334911ac0194d16a3324f7e57c37</url>
  <id>bd348cbda136334911ac0194d16a3324f7e57c37</id>
  <committed-date>2007-05-25T15:47:42-07:00</committed-date>
  <authored-date>2007-05-25T15:47:42-07:00</authored-date>
  <message>per user tagging, without breaking not per user tagging, needs a bit of cleanup and testing

git-svn-id: http://svn.devjavu.com/geemus/rails/plugins/acts_as_taggable_redux@3 89c3609e-b12b-0410-95a9-e792c7af2e16</message>
  <tree>11b84f53eb8f0d3495556671775e73b16e270349</tree>
  <committer>
    <name>monki@geemus.com</name>
    <email>monki@geemus.com@89c3609e-b12b-0410-95a9-e792c7af2e16</email>
  </committer>
</commit>
