The Model Image has many Tags
When i run this query to get Images with tags that are named both bamboo in and Green i get an error that says the alias table is not present. What am I doing wrong? Image.joins(:tags).select("images.*, count(tags.id) as 'tags_count'").where(tags:{name:["bamboo","Green"]}).group("images.id").having("tags_count = 2") Error *Image Load (0.4ms)* SELECT images.*, count(tags.id) as tags_count FROM "images" INNER JOIN "image_tags" ON "image_tags"."image_id" = "images"."id" INNER JOIN "tags" ON "tags"."id" = "image_tags"."tag_id" WHERE "tags"."name" IN ('bamboo', 'Green') GROUP BY images.id HAVING tags_count = 2 PG::UndefinedColumn: ERROR: column "tags_count" does not exist LINE 1: ... IN ('bamboo', 'Green') GROUP BY images.id HAVING tags_count... ^ : SELECT images.*, count(tags.id) as tags_count FROM "images" INNER JOIN "image_tags" ON "image_tags"."image_id" = "images"."id" INNER JOIN "tags" ON "tags"."id" = "image_tags"."tag_id" WHERE "tags"."name" IN ('bamboo', 'Green') GROUP BY images.id HAVING tags_count = 2 ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column "tags_count" does not exist LINE 1: ... IN ('bamboo', 'Green') GROUP BY images.id HAVING tags_count... -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c5e93122-3e6a-4e48-907d-79600d819b74%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.