tj / dm-pagination

Better DataMapper paging solution - framework independant - like will_paginate but better ;)
55 stars 19 forks source link

PostgresError #23

Closed jpgarcia closed 14 years ago

jpgarcia commented 14 years ago

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 commented 14 years ago

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 commented 14 years ago

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

jpgarcia commented 14 years ago

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 commented 14 years ago

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

tj commented 14 years ago

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 commented 14 years ago

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

jpgarcia commented 14 years ago

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 commented 14 years ago

My bad! typo, 1.0.1 fixes this