#263 new
friofool

wrong count results

Reported by friofool | February 11th, 2009 @ 06:35 PM

hi,

this is my log :

SQL (3.1ms) SELECT count(*) AS count_all, mifo.mod_icom_option_id,mip.id AS mifo_mod_icom_option_id_mip_id FROM mod_icom_files_options as mifo inner join mod_icom_prods as mip on (mifo.mod_icom_prod_id = mip.id) inner join mod_icom_marque_prods as mimp on (mip.id = mimp.mod_icom_prod_id) where mip.visibilite_prod = 1 AND mip.statut_promo !='destockage' and mifo.valide = 1 and mip.visibilite_prod = 1 and mimp.mod_icom_marque_id = 45 GROUP BY mifo.mod_icom_option_id,mip.id

If i tun this query in sql database client i found 28 results but the count method return 18 records (i add a logger in the wp_count method).

I set the :per_page => 9, and the view method display 2 pages.

But if i try to change manually the page number parameter in the url to 3, the helper show me 4 pages who is the correct value.

Is there a bug ?

Comments and changes to this ticket

  • Mislav

    Mislav February 11th, 2009 @ 07:23 PM

    I don't think there is a bug - both find and count use the built-in ActiveRecord methods.

    You haven't given me enough information. First tell me the will_paginate version, then Rails version, then paste the code that performs this paginating find and count.

  • friofool

    friofool February 11th, 2009 @ 09:22 PM

    will_paginate : mislav-will_paginate-2.3.6

    rails : 2.2.2

    and my request :

    conditions = "inner join mod_icom_prods as mip on (mifo.mod_icom_prod_id = mip.id)"

    conditions += " inner join mod_icom_marque_prods as mimp on (mip.id = mimp.mod_icom_prod_id)"

    conditions += "where mip.visibilite_prod = 1 AND mip.statut_promo ='destockage' and mifo.valide = 1 and mip.visibilite_prod = 1 and mimp.mod_icom_marque_id = 45"

    ModIcomFilesOption.paginate(:all,

                            :select => "mifo.id,mifo.filename,mifo.mod_icom_option_id,mifo.mod_icom_prod_id",
                                      :joins => "as mifo " + conditions,
                                      :per_page  =>  9,
                                      :page => params[:page],
                                      :group => "mifo.mod_icom_option_id,mip.id",
                                      :order => " mimp.position_prod asc"
                                      )
    
    

    for the count method i tried to put a logger in wp_count method on the finder module :

    .... logger.info("-----" + count.length.to_s) count.respond_to?(:length) ? count.length : count end

    thanks for your help

  • friofool

    friofool February 12th, 2009 @ 09:43 AM

    i use the solution in this post :

    http://groups.google.com/group/w...

    count results are wrong when a "group by" clause appear in the query.

    sorry for the inconvenience

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Everyone's favorite Ruby library for pagination of practically anything!

People watching this ticket

Tags

Pages