mbleigh / acts-as-taggable-on

A tagging plugin for Rails applications that allows for custom tagging along dynamic contexts.
http://mbleigh.lighthouseapp.com/projects/10116-acts-as-taggable-on
MIT License
4.96k stars 1.2k forks source link

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

Open amirali-ashraf opened 3 years ago

amirali-ashraf commented 3 years ago

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 commented 3 years ago

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
yamitake commented 1 year ago

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 commented 11 months ago

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.