Skip to content

Invalid query when running some class methods? #32

@antonysastre

Description

@antonysastre

Running: PostgreSQL 11

Gemfile.lock
    acts-as-taggable-array-on (0.6.0)
      activerecord (>= 4)
      activesupport (>= 4)
class Photo < ApplicationRecord
  taggable_array :tags
end

> Photo.last.tags => ["coffee", "sun"]
> Photo.with_any_tags("coffee") => [#<Photo: …>, #<Photo: …>]
> Photo.tags_cloud => ActiveRecord::StatementInvalid: PG::UndefinedTable

Running Photo.tags_cloud or seems to produce invalid query:

DEPRECATION WARNING: Dangerous query method (method whose arguments are used as raw SQL) called with non-attribute argument(s): "tag, count(*) as count". Non-attribute arguments will be disallowed in Rails 6.0. This method should not be called with user-provided values, such as request parameters or model attributes. Known-safe values can be passed by wrapping them in Arel.sql(). (called from __pry__ at (pry):4)

   (1.4ms)  SELECT tag, count(*) as count FROM (SELECT unnest(photos.tags) as tag FROM "photos") subquery GROUP BY tag ORDER BY "photos"."created_at" DESC, tag
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  missing FROM-clause entry for table "photos" 

LINE 1: ...tag FROM "photos") subquery GROUP BY tag ORDER BY "photos"."...
                                                             ^
: SELECT tag, count(*) as count FROM (SELECT unnest(photos.tags) as tag FROM "photos") subquery GROUP BY tag ORDER BY "photos"."created_at" DESC, tag
from /Users/antonysastre/.rvm/gems/ruby-2.5.0/gems/activerecord
-5.2.0.rc2/lib/active_record/connection_adapters/postgresql_adapter.rb:603:in `async_exec'

Update: Getting the same error on Photo.all_tags.
Update: Updated to 0.6.0, same issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions