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

using "tagged_with" with .uniq or .select(distinct(...) throws DISTINCT error #357

Closed
christopherdro opened this issue Apr 28, 2013 · 5 comments · Fixed by #496
Closed
Labels
Milestone

Comments

@christopherdro
Copy link

Take a look under https://gist.github.com/casheghian/e1b7fd206d6434f4972b to see the search method I am using.

When using the commented out line everything works great, however I am left with duplicate results.

Using the current join and select statement or .uniq on what returns throws a
"PG::Error: ERROR: syntax error at or near "DISTINCT"
LINE 1: SELECT distinct(restaurants.id), restaurants.*, DISTINCT res.."

@prikha
Copy link

prikha commented Oct 17, 2013

Confirm this!

@developer88
Copy link
Contributor

I can confirm that - it happens when you add { any: true } option. I do believe this is because of the string in core.rb:

select_clause = "DISTINCT #{table_name}.*" unless context and tag_types.one?

and if you make a complex request all this select query added to other part of your request as is.

Tested it in 3.0.1 and 2.4.2

My solution: #461

@leklund
Copy link
Contributor

leklund commented Mar 18, 2014

The merged commit seems to call .uniq for any tagged_with query. I discovered this because I have json columns on many of my tables. If a table has a json column, using a distinct or a uniq will raise an error:

PG::UndefinedFunction: ERROR:  could not identify an equality operator for type json

Using this commit, every call to Model.tagged_with will raise this error. Before it would only raise the error when using any:true as it would include the distinct in the select.

@seuros
Copy link
Collaborator

seuros commented Mar 18, 2014

Any tests to reproduce the bug ?
I'm closing this issue since that a new bug

@seuros seuros closed this as completed Mar 18, 2014
@leklund
Copy link
Contributor

leklund commented Mar 18, 2014

Here is a test to reproduce. I'll see about creating a new bug.

  it "shouldn't generate a query with DISTINCT by default" do
    @taggable.skill_list = "ruby, rails, css"
    @taggable.save

    TaggableModel.tagged_with('ruby').to_sql.should_not match /DISTINCT/
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants