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

How to remove SELECT expressions in query #22

Open
ealymbaev opened this issue Nov 6, 2014 · 3 comments
Open

How to remove SELECT expressions in query #22

ealymbaev opened this issue Nov 6, 2014 · 3 comments

Comments

@ealymbaev
Copy link

The gem adds the SELECT expressions like

"jobs"."id" AS t0_r0, "jobs"."job_description" AS t0_r1, .......

They cause error when using COUNT and GROUP BY functions in Postgres:

PG::GroupingError: ERROR: column "jobs.id" must appear in the GROUP BY clause or be used in an aggregate function

How can I remove them from the query?

P.S.

The rails code is:

states = Job.joins(listing: :location).select('count(locations.state) as count, locations.state').group('locations.state')

@ddarren
Copy link

ddarren commented Nov 10, 2014

I'm having a similar problem when grouping. I'd be happy with a hack for the time being to get this working.

@mintuhouse
Copy link
Contributor

+1
I am trying to join a third table and select columns from it in vain. Does anyone know of a way to select required columns from third table?

@mintuhouse
Copy link
Contributor

Use .unscoped to remove the default_scope

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

3 participants