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.98k stars 1.2k forks source link

Json field on a model causes find_related_* to stop working #1026

Open denkozlovs opened 3 years ago

denkozlovs commented 3 years ago
2.6.5 :002 > w.find_related_tags
  ActsAsTaggableOn::Tag Load (7.1ms)  SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = $1 AND "taggings"."taggable_type" = $2 AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL)  [["taggable_id", 6], ["taggable_type", "Worker"]]
  FemaleWorker Load (10.0ms)  SELECT workers.*, COUNT(tags.id) AS count FROM workers, tags, taggings WHERE "workers"."type" = $1 AND "workers"."deleted_at" IS NULL AND ("workers"."id" != 6 AND workers.id = taggings.taggable_id AND taggings.taggable_type = 'Worker' AND taggings.tag_id = tags.id AND tags.name IN ('welcoming','sport') AND taggings.context = 'tags') GROUP BY workers.id, workers.published_at, workers.user_id, workers.company_id, workers.name, workers.created_at, workers.updated_at, workers.paid_seconds, workers.district_id, workers.state, workers.city_id, workers.tariff, workers.published_till, workers.moderated_update, workers.type ORDER BY count DESC LIMIT $2  [["type", 1], ["LIMIT", 11]]
Traceback (most recent call last):
ActiveRecord::StatementInvalid (PG::UndefinedFunction: ERROR:  could not identify an equality operator for type json)
LINE 1: ...cription, workers.tariff, workers.published_till, workers.mo...
                                                             ^

moderated_update is a json field, on schema.rb:

    t.json "moderated_update"

any thoughts on how to bypass this?

mmagn commented 1 year ago

Still relevant for v9.0.1. Is there a way to bypass the problem ?

mmagn commented 1 year ago

After migrating the json column in jsonb the error is gone.

Solution found here : https://stackoverflow.com/a/70629577/11764080