Forum: Ruby on Rails MySQL and Postgres

Fb15b4025c2802a463003269ca4ce869?d=identicon&s=25 Miguel A. (miguel_a85)
on 2012-05-29 14:48
Hello all,

I'm a RoR begginer and am developing my app using MySQL but Heroku uses
Postgres, so my arel isn't working quite properly.

I've searched about the outputted error but in my case, since I'm doing
a query between a HABTM table, things aren't going so well.

Basically, a Product has_and_belongs_to_many Categories. My relation is
all set and everything works locally, but on deploy a 500 error occurs.

So without further delay, the issue is:

(...previous queries that work good locally and on heroku...)
if params[:fc].present? (checks if checkboxes have been ticked)
          arel=arel.joins('INNER JOIN categories_products ON
products.id=categories_products.product_id')
          arel=arel.where('categories_products.category_id in
(:fc_list)', :fc_list => params[:fc]).uniq
          arel=arel.group('product_id').having('count(category_id) =
:size', :size => params[:fc].size)
 end

So the idea is to allow the user to check a checkbox list and then
display
all the products that are in the checked categories.

My heroku error is: "products.id" must appear in the GROUP BY clause or
be used in an aggregate function.

I know that there are already threads on this but none have fixed my
problem.

Thank you in advance.

Regards,
Miguel A.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.