The model:
class Content < ActiveRecord::Base
acts_as_taggable
end
created with:
class CreateContents < ActiveRecord::Migration
def change
create_table :contents do |t|
t.text :name
t.json :options
t.timestamps
end
end
end
errors given existing content and tags. Content.tagged_with generates a query with a SELECT DISTINCT
even when it doesn't need to.
> Content.all.map(&:tag_list).flatten
Content Load (0.9ms) SELECT "contents".* FROM "contents"
ActsAsTaggableOn::Tag Load (1.4ms) 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", 1], ["taggable_type", "Content"]]
=> ["lorem", "ipsum", "dolor"]
> Content.tagged_with('lorem')
ActsAsTaggableOn::Tag Load (5.3ms) SELECT "tags".* FROM "tags" WHERE (lower(name) = 'lorem')
Content Load (2.2ms) SELECT DISTINCT "contents".* FROM "contents" JOIN taggings contents_taggings_d79ced2 ON contents_taggings_d79ced2.taggable_id = "contents".id AND contents_taggings_d79ced2.taggable_type = 'Content' AND contents_taggings_d79ced2.tag_id = 1
PG::UndefinedFunction: ERROR: could not identify an equality operator for type json
...
> Content.tagged_with(['lorem','ipsum'], any:true)
ActsAsTaggableOn::Tag Load (1.1ms) SELECT "tags".* FROM "tags" WHERE (lower(name) = 'lorem' OR lower(name) = 'ipsum')
Content Load (1.2ms) SELECT DISTINCT contents.* FROM "contents" JOIN taggings conte_taggings_b7dee94 ON conte_taggings_b7dee94.taggable_id = "contents".id AND conte_taggings_b7dee94.taggable_type = 'Content' WHERE (conte_taggings_b7dee94.tag_id = 1 OR conte_taggings_b7dee94.tag_id = 2)
PG::UndefinedFunction: ERROR: could not identify an equality operator for type json
...