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

PostgresError #23

Closed
jpgarcia opened this issue Dec 6, 2009 · 8 comments
Closed

PostgresError #23

jpgarcia opened this issue Dec 6, 2009 · 8 comments

Comments

@jpgarcia
Copy link

jpgarcia commented Dec 6, 2009

I'm getting this when running on Heroku because of Postgres database:

PostgresError - ERROR: column "medium.sector" must appear in the GROUP BY clause or be used in an aggregate function

Query: SELECT COUNT(*) FROM "medium" ORDER BY "sector" DESC:

BTW: running it locally with sqlite3 is working like a charm, thanks for the gem!

@jpgarcia
Copy link
Author

jpgarcia commented Dec 6, 2009

I fixed it by adding a line ( query.delete :order ) in the page method, agree with that?:

def page page = nil, options = {}
  options, page = page, nil if page.is_a? Hash
  page ||= pager_option :page, options
  options.delete :page
  page = 1 unless (page = page.to_i) && page > 1
  per_page = pager_option(:per_page, options).to_i
  query = options.dup
  collection = new_collection scoped_query(options = {
    :limit => per_page,
    :offset => (page - 1) * per_page,
    :order => [:id.desc]
  }.merge(query))
  query.delete :order <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  options.merge! :total => count(query), :page => page
  collection.pager = DataMapper::Pager.new options
  collection
end

@tj
Copy link
Owner

tj commented Dec 6, 2009

That is something to take up with DM core, I would not go explicitly deleting :order, because it works fine with other RDMS

@jpgarcia
Copy link
Author

jpgarcia commented Dec 6, 2009

Ok, anyway removing the option :order will not affect the collection itself, I'm removing the :order only for the aggregate function "count", because the order hasn't any sense for an aggregate function.
thanks for your quickly answer!

@tj
Copy link
Owner

tj commented Dec 6, 2009

ah, right sorry didnt look closely enough lol its probably fine then

@tj
Copy link
Owner

tj commented Dec 7, 2009

Cool cool I committed the change :D thanks. Your totally right though I just had read it wrong originally when I scanned over the issue

@jpgarcia
Copy link
Author

jpgarcia commented Dec 7, 2009

good man! now I'm going to remove the monkey patch :)

@jpgarcia
Copy link
Author

hi visionmedia, it's been a long time since my last message and untill now I didn't deployed the app to heroku and now I'm realizing that the gem still throwing the same exception, this is because you removed the :order option to the 'options' instead of to the 'query' as I wrote in my second message.
hope you can modify it for the next version.

@tj
Copy link
Owner

tj commented Dec 19, 2009

My bad! typo, 1.0.1 fixes this

This issue was closed.
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