Note that there are some explanatory texts on larger screens.

plurals
  1. POacts-as-taggable-on creates duplicate rows in database
    primarykey
    data
    text
    <p>I am using acts-as-taggable-on for a Rails application and every time I create a new Photo (for example) I get duplicate rows in the 'taggings' table.</p> <p>My model classes look something like:</p> <pre><code>class User &lt; ActiveRecord::Base acts_as_tagger ... end </code></pre> <p>and </p> <pre><code>class Photo &lt; ActiveRecord::Base acts_as_taggable_on :tags ... end </code></pre> <p>and in the create action of my photos_controller</p> <pre><code>def create @user = current_user ... @user.tag(@photo, :with =&gt; params[:photo][:tag_list], :on =&gt; :tags) ... end </code></pre> <p>The strange thing is that I get duplicate rows in the 'taggings' table where the first row has 'tagger_id' and 'tagger_type' set to NULL while the duplicate row has the correct values.</p> <p>my Gemfile looks like this</p> <pre><code>gem 'rails', '3.2.8' gem 'acts-as-taggable-on', '~&gt; 2.3.1' </code></pre> <p>Has anyone seen this behavior before? Is it a configuration problem on my end?</p> <p>Update: Looking at the console I can clearly see two transactions being performed and in the first one there is this:</p> <pre><code>SQL (0.6ms) INSERT INTO "taggings" ("context", "created_at", "tag_id", "taggable_id", "taggable_type", "tagger_id", "tagger_type") VALUES (?, ?, ?, ?, ?, ?, ?) [["context", "tags"], ["created_at", Thu, 27 Sep 2012 21:49:22 UTC +00:00], ["tag_id", 12], ["taggable_id", 10], ["taggable_type", "Photo"], ["tagger_id", nil], ["tagger_type", nil]] </code></pre> <p>and it is clear that tagger_id is set to null as well as tagger_type.</p> <p>Here is a full console output, I have separated the lines to help read it. You will notice two separate transactions and in the first one there is the insert with NULL values while at the end of the second one you will see the correct one.</p> <p>Started POST "/photo" for 127.0.0.1 at 2012-09-28 07:39:58 +0200 Processing by PhotoController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"IOmnfDpU7V7vYw3h6RXXzXPsXf/B0fcVihXhb+S8JHU=", "photo"=>{"url"=>"www.another.com/photo.jpg", "title"=>"Another", "tag_list"=>"a_tag", "description"=>"", "private"=>"0"}, "commit"=>"Add Photo"} Redirected to <a href="http://www.somedomain.com:3000/users/christiangiacomi" rel="nofollow">http://www.somedomain.com:3000/users/christiangiacomi</a></p> <p>Completed 302 Found in 414ms (ActiveRecord: 20.5ms)</p> <p>User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."username" = 'christiangiacomi' LIMIT 1 ActsAsTaggableOn::Tag Load (0.2ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" IS NULL AND "taggings"."taggable_type" = 'Photo' AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL)</p> <p>(0.1ms) begin transaction</p> <p>SQL (6.2ms) INSERT INTO "photos" ("created_at", "description", "favorite", "private", "title", "updated_at", "url", "user_id") VALUES (?, ?, ?, ?, ?, ?, ?, ?) [["created_at", Fri, 28 Sep 2012 05:39:59 UTC +00:00], ["description", ""], ["favorite", false], ["private", false], ["title", "Another"], ["updated_at", Fri, 28 Sep 2012 05:39:59 UTC +00:00], ["url", "http://www.another.com/photo.jpg"], ["user_id", 1]]</p> <p>ActsAsTaggableOn::Tag Load (3.2ms) SELECT "tags".* FROM "tags" WHERE (lower(name) = 'a_tag') ActsAsTaggableOn::Tag Exists (0.1ms) SELECT 1 AS one FROM "tags" WHERE "tags"."name" = 'a_tag' LIMIT 1</p> <p>SQL (0.2ms) INSERT INTO "tags" ("name") VALUES (?) [["name", "a_tag"]]</p> <p>ActsAsTaggableOn::Tag Load (0.1ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = 13 AND "taggings"."taggable_type" = 'Photo' AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL)</p> <p>ActsAsTaggableOn::Tagging Exists (0.2ms) SELECT 1 AS one FROM "taggings" WHERE ("taggings"."tag_id" = 16 AND "taggings"."taggable_type" = 'Photo' AND "taggings"."taggable_id" = 13 AND "taggings"."context" = 'tags' AND "taggings"."tagger_id" IS NULL AND "taggings"."tagger_type" IS NULL) LIMIT 1</p> <p>SQL (0.7ms) INSERT INTO "taggings" ("context", "created_at", "tag_id", "taggable_id", "taggable_type", "tagger_id", "tagger_type") VALUES (?, ?, ?, ?, ?, ?, ?) [["context", "tags"], ["created_at", Fri, 28 Sep 2012 05:39:59 UTC +00:00], ["tag_id", 16], ["taggable_id", 13], ["taggable_type", "Photo"], ["tagger_id", nil], ["tagger_type", nil]]</p> <p>(4.1ms) commit transaction</p> <p>(0.1ms) begin transaction</p> <p>ActsAsTaggableOn::Tag Load (0.2ms) SELECT "tags".* FROM "tags" WHERE (lower(name) = 'a_tag')</p> <p>ActsAsTaggableOn::Tag Load (0.2ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = 13 AND "taggings"."taggable_type" = 'Photo' AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL)</p> <p>CACHE (0.0ms) SELECT "tags".* FROM "tags" WHERE (lower(name) = 'a_tag')</p> <p>ActsAsTaggableOn::Tag Load (0.2ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = 13 AND "taggings"."taggable_type" = 'Photo' AND (taggings.context = 'tags' AND taggings.tagger_id = 1 AND taggings.tagger_type = 'User')</p> <p>ActsAsTaggableOn::Tagging Exists (0.4ms) SELECT 1 AS one FROM "taggings" WHERE ("taggings"."tag_id" = 16 AND "taggings"."taggable_type" = 'Photo' AND "taggings"."taggable_id" = 13 AND "taggings"."context" = 'tags' AND "taggings"."tagger_id" = 1 AND "taggings"."tagger_type" = 'User') LIMIT 1</p> <p>SQL (0.5ms) INSERT INTO "taggings" ("context", "created_at", "tag_id", "taggable_id", "taggable_type", "tagger_id", "tagger_type") VALUES (?, ?, ?, ?, ?, ?, ?) [["context", "tags"], ["created_at", Fri, 28 Sep 2012 05:39:59 UTC +00:00], ["tag_id", 16], ["taggable_id", 13], ["taggable_type", "Photo"], ["tagger_id", 1], ["tagger_type", "User"]]</p> <p>(2.4ms) commit transaction</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload