acts-as-taggable-on icon indicating copy to clipboard operation
acts-as-taggable-on copied to clipboard

Using different column instead of id for taggable_id or Using the Id column as UUID in MySQL

Open amirali-ashraf opened this issue 4 years ago • 3 comments

I want to tag a model that does not have any field called id instead I am going to use another field that is used as id in my table called customerNumber. I want to know if there is any way to override the id with another field to store it in the tagging table.

amirali-ashraf avatar Dec 16 '20 14:12 amirali-ashraf

I have decided to use the table's id instead and I have another issue in front. UUID does not work for me since it returns 0 for id instead of the intended UUID. I am using MySQL and using uuid as the type also did not help os I changed it to:

      t.references :taggable, polymorphic: true, type: :string
      t.references :tagger, polymorphic: true, type: :string

amirali-ashraf avatar Dec 16 '20 18:12 amirali-ashraf

I have the same problem. is it possible to make the taggable_id a string and have the model id work for both bigint and UUID?

yamitake avatar Aug 18 '23 02:08 yamitake

I try this code.

 User.joins("INNER JOIN taggings ON taggings.taggable_id = CAST(posts.id AS VARCHAR) AND taggings.taggable_type = 'User'")
                .joins("INNER JOIN tags ON tags.id = taggings.tag_id")
                .where(taggings: { context: "tags" })
                .where(tags: { name: "test_tag_name" })

I would like to know how to move but cleanly solve the problem.

yamitake avatar Sep 21 '23 10:09 yamitake