Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tagged_with incompatible with UUID (Rails 4) #397

Closed
xph opened this issue Sep 6, 2013 · 1 comment
Closed

tagged_with incompatible with UUID (Rails 4) #397

xph opened this issue Sep 6, 2013 · 1 comment
Labels

Comments

@xph
Copy link

xph commented Sep 6, 2013

In a Rails 4 app, there is the built-in option to use UUID the primary key in postgresql. It is possible to modify the migration template generated in order to support UUID primary keys. However, the function tagged_with breaks, because the primary key is hardcoded and presumed to be an integer in the following SQL queries:

joins <<  "JOIN #{ActsAsTaggableOn::Tagging.table_name}" +
                      "  ON #{ActsAsTaggableOn::Tagging.table_name}.taggable_id = #{quote}#{table_name}#{quote}.#{primary_key}" +
                      " AND #{ActsAsTaggableOn::Tagging.table_name}.taggable_type = #{quote_value(base_class.name)}" +
                      " AND #{ActsAsTaggableOn::Tagging.table_name}.tagger_id = #{owned_by.id}" +
                      " AND #{ActsAsTaggableOn::Tagging.table_name}.tagger_type = #{quote_value(owned_by.class.base_class.to_s)}"

and

conditions << tags.map { |t| "#{taggings_alias}.tag_id = #{t.id}" }.join(" OR ")

and finally

tagging_join  = "JOIN #{ActsAsTaggableOn::Tagging.table_name} #{taggings_alias}" +
                            "  ON #{taggings_alias}.taggable_id = #{quote}#{table_name}#{quote}.#{primary_key}" +
                            " AND #{taggings_alias}.taggable_type = #{quote_value(base_class.name)}" +
                            " AND #{taggings_alias}.tag_id = #{tag.id}"

Basically anything that contains #{something.id} will not work. There might be more, I'm not sure. I did a search for the string "id}" and these three came up. Because there are no quotes around the ID (assumed integer), the query breaks when the primary key is actually the UUID type and the quotes are needed.

Edit: formatting.

@skirchmeier
Copy link

Nice @awt. Looking forward to taking advantage of this.

@bf4 bf4 closed this as completed Jan 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants