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

The tagged_with method paired with the on: option does not work correctly #1002

Open thontaddeo opened 4 years ago

thontaddeo commented 4 years ago

The tagged_with method paired with the on: parameter builds a query with a <= SQL operator rather than an explicit = operator. This causes models with multiple acts_as_taggable_on fields to return incorrect results.

For example,

Model.tagged_with('tagName', on: :taggable_field).count
SELECT COUNT(*) FROM "recipes" INNER JOIN "taggings" "model_taggings" ON "model_taggings"."taggable_id" = "models"."id" AND "model_taggings"."taggable_type" = 'Model' AND "model_taggings"."tag_id" IN (SELECT "tags"."id" FROM "tags" WHERE "tags"."name" ILIKE 'tagName') AND "model_taggings"."context" <= 'taggable_field'
rcastillo-eastrock commented 11 months ago

+1