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

Count on tagged_with / group_by query #405

Open
ghost opened this issue Sep 18, 2013 · 8 comments
Open

Count on tagged_with / group_by query #405

ghost opened this issue Sep 18, 2013 · 8 comments
Labels

Comments

@ghost
Copy link

ghost commented Sep 18, 2013

This query works perfectly

Criterion.tagged_with(["java"], on: :skills).count

But adding a group_by clause breaks everything :

Criterion.tagged_with(["java"], on: :skills).group(:minimum_salary).count
ActiveRecord::StatementInvalid: PG::Error: ERROR:  syntax error at or near "AS"
SELECT COUNT(*) AS count_all,  AS , minimum_salary AS minimum_salary FROM "criterions" JOIN ...
@rgould
Copy link
Contributor

rgould commented Oct 4, 2013

I'm experiencing this as well.

@rgould
Copy link
Contributor

rgould commented Oct 5, 2013

Found a fix and issued a pull request:

#417

@ghost
Copy link
Author

ghost commented Dec 10, 2013

Thx for the workaround @rgould ! I was still experimenting this problem.

@bf4
Copy link
Collaborator

bf4 commented Dec 10, 2013

Trying to get master tests reliably passing, then will start merging again soon :)

@ghost
Copy link
Author

ghost commented Dec 10, 2013

OK I'll test it against your merge as soon as you'll release it !

@bf4
Copy link
Collaborator

bf4 commented Dec 10, 2013

@beg if you want to take a look, I've been unable to duplicate the sqlite3 failure I see on travis #430

@ghost
Copy link
Author

ghost commented Dec 10, 2013

My table definition

    create_table "criterions", force: true do |t|
      t.integer  "user_id"
      t.integer  "minimum_salary"
    ...
    end

The class itself :

class Criterion < ActiveRecord::Base
   acts_as_ordered_taggable_on :skills
...

The request that fails without the monkey patch of @rgould

Criterion.tagged_with(["java"], on: :skills).group(:minimum_salary).count
SELECT COUNT(*) AS count_all,  AS , minimum_salary AS minimum_salary FROM "criterions" JOIN taggings criterions_taggings_68443c0  ON criterions_taggings_68443c0.taggable_id = "criterions".id AND criterions_taggings_68443c0.taggable_type = 'Criterion' AND criterions_taggings_68443c0.tag_id = 3312 AND criterions_taggings_68443c0.context = 'skills' GROUP BY minimum_salary

You can see that there's a 'AS' in the middle of nowhere.
The monkey patch prevails from this.

 group = [] # Rails interprets this as a no-op in the group() call below

@bf4
Copy link
Collaborator

bf4 commented Dec 10, 2013

Can you rebase against master and force push?

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

No branches or pull requests

2 participants