Carson
2008-May-10 15:04 UTC
Paginating a find statement with :select => "distinct products.* "
My selection of products from a Products table looks like this:
# Get products on department promotion
@products = Product.find(:all,
:select => "distinct products.*",
:order => " product_id ",
:joins => " inner join category_products " +
" on products.product_id category_products.product_id
" +
" inner join categories " +
" on category_products.category_id categories.category_id
",
:conditions => ["products.on_department_promotion = ? " +
" AND categories.department_id = ?", true, params[:id]])
When I try to substitute a pagination statement for the find
statement, for example:
@products = Product.paginate(:all,
:page => params[:page],
:select => "distinct products.*",
:order => " product_id ",
:joins => " inner join category_products " +
" on products.product_id category_products.product_id
" +
" inner join categories " +
" on category_products.category_id categories.category_id
",
:conditions => ["products.on_department_promotion = ? " +
" AND categories.department_id = ?", true, params[:id]])
the paginage gem/plugin can''t interpret the select distinct statement
an typically gives an error like:
SQLite3::SQLException: near "*": syntax error: SELECT
count(distinct
products.*) AS count_distinct_products_all FROM products inner
join
etc., etc., etc.
Can anyone tell me how to paginate the results of the original find
statement?
Carson
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---