Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.1.0 breaks with PostgreSQL tables that have json columns #506

Closed
leklund opened this issue Apr 3, 2014 · 1 comment
Closed

3.1.0 breaks with PostgreSQL tables that have json columns #506

leklund opened this issue Apr 3, 2014 · 1 comment

Comments

@leklund
Copy link
Contributor

leklund commented Apr 3, 2014

Setup: vanilla Rails 4.0.4 app using PostgreSQL 9.3. The 3.1.0 release breaks when using tagged_with on a model that utilizes a json column.

The tagged_with method is calling .uniq on every request and that in turn generates a query with a distinct table.* which breaks with json columns. See this pull request for a possible solution: #496

migration:

class CreatePosts < ActiveRecord::Migration
  def change
    create_table :posts do |t|
      t.text :title
      t.text :content
      t.json :options

      t.timestamps
    end
  end
end

the model

class Post < ActiveRecord::Base
  acts_as_taggable
end

the error in action:

> Post.create(title:'one', tag_list:'lorem')
> Post.create(title:'two', tag_list:'lorem,ipsum')
> Post.create(title:'three', tag_list:'ipsum,dolor')
> Post.tagged_with('lorem')
> ActsAsTaggableOn::Tag Load (0.8ms)  SELECT "tags".* FROM "tags" WHERE (LOWER(name) = LOWER('lorem'))
  Post Load (0.9ms)  SELECT DISTINCT "posts".* FROM "posts" JOIN taggings posts_taggings_861d63c ON posts_taggings_861d63c.taggable_id = "posts".id AND posts_taggings_861d63c.taggable_type = 'Post' AND posts_taggings_861d63c.tag_id = 1
PG::UndefinedFunction: ERROR:  could not identify an equality operator for type json
LINE 1: SELECT DISTINCT "posts".* FROM "posts" JOIN taggings posts_t...
@seuros
Copy link
Collaborator

seuros commented Apr 4, 2014

this is related to #496 , we should merge this PR once the tests pass.

leklund added a commit to leklund/acts-as-taggable-on that referenced this issue Apr 4, 2014
updated specs for 'select distinct' and pg issues

* new model/table with a json column for postgresql specific testing
* add tests for explicit distinct in a select and for all queries to
  test if tagged_with adds a distinct clause on the query.
  http://github.com/mbleigh/acts-as-taggable-on/issues/357
* add tests for taggable_model_with_json
* exclude test should sort the array result and expected array.
  PostgreSQL won't always return the two expected results in
  the expected order so the test failed intermittently.

use group vs distinct when options[:any] is true

update CHANGELOG

check pg version and only use json if >=9.2
leklund added a commit to leklund/acts-as-taggable-on that referenced this issue Apr 9, 2014
fix bug mbleigh#506 - .uniq breaks with pg and json columns

updated specs for 'select distinct' and pg issues

* new model/table with a json column for postgresql specific testing
* add tests for explicit distinct in a select and for all queries to
  test if tagged_with adds a distinct clause on the query.
  http://github.com/mbleigh/acts-as-taggable-on/issues/357
* add tests for taggable_model_with_json
* exclude test should sort the array result and expected array.
  PostgreSQL won't always return the two expected results in
  the expected order so the test failed intermittently.

use group vs distinct when options[:any] is true

update CHANGELOG

check pg version and only use json if >=9.2

move change to master section
leklund added a commit to leklund/acts-as-taggable-on that referenced this issue Apr 23, 2014
fix bug mbleigh#506 - .uniq breaks with pg and json columns

updated specs for 'select distinct' and pg issues

* new model/table with a json column for postgresql specific testing
* add tests for explicit distinct in a select and for all queries to
  test if tagged_with adds a distinct clause on the query.
  http://github.com/mbleigh/acts-as-taggable-on/issues/357
* add tests for taggable_model_with_json
* exclude test should sort the array result and expected array.
  PostgreSQL won't always return the two expected results in
  the expected order so the test failed intermittently.

use group vs distinct when options[:any] is true

update CHANGELOG

check pg version and only use json if >=9.2

move change to master section
leklund added a commit to leklund/acts-as-taggable-on that referenced this issue Apr 23, 2014
fix bug mbleigh#506 - .uniq breaks with pg and json columns

updated specs for 'select distinct' and pg issues

* new model/table with a json column for postgresql specific testing
* add tests for explicit distinct in a select and for all queries to
  test if tagged_with adds a distinct clause on the query.
  http://github.com/mbleigh/acts-as-taggable-on/issues/357
* add tests for taggable_model_with_json
* exclude test should sort the array result and expected array.
  PostgreSQL won't always return the two expected results in
  the expected order so the test failed intermittently.

use group vs distinct when options[:any] is true

update CHANGELOG

check pg version and only use json if >=9.2

move change to master section

move table with json to spec/internal/db/schema.rb
@seuros seuros closed this as completed in fc4066e May 1, 2014
tekniklr pushed a commit to tekniklr/acts-as-taggable-on that referenced this issue Mar 19, 2021
fix bug mbleigh#506 - .uniq breaks with pg and json columns

updated specs for 'select distinct' and pg issues

* new model/table with a json column for postgresql specific testing
* add tests for explicit distinct in a select and for all queries to
  test if tagged_with adds a distinct clause on the query.
  http://github.com/mbleigh/acts-as-taggable-on/issues/357
* add tests for taggable_model_with_json
* exclude test should sort the array result and expected array.
  PostgreSQL won't always return the two expected results in
  the expected order so the test failed intermittently.

use group vs distinct when options[:any] is true

update CHANGELOG

check pg version and only use json if >=9.2

move change to master section

move table with json to spec/internal/db/schema.rb
tekniklr pushed a commit to tekniklr/acts-as-taggable-on that referenced this issue Mar 19, 2021
…pg_and_json

Leklund fix distinct for pg and json fixes mbleigh#506
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants