简体   繁体   English

Ruby on Rails-MySQL和PostGres

[英]Ruby on Rails - MySQL and PostGres

I'm a RoR begginer and am developing my app using MySQL but Heroku uses Postgres, so my arel isn't working quite properly. 我是RoR的初学者,正在使用MySQL开发我的应用程序,但Heroku使用Postgres,因此我的竞技场无法正常工作。

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. 我已经搜索了所输出的错误,但就我而言,由于我正在HABTM表之间进行查询,因此运行得不太顺利。

Basically, a Product has_and_belongs_to_many Categories. 基本上,一个产品具有“ _and_belongs_to_many”类别。 My relation is all set and everything works locally , but on deploy a 500 error occurs. 我的关系已经设置好,一切都在本地运行 ,但是在部署时会发生500错误。

So without further delay, the issue is: 因此,在没有进一步拖延的情况下,问题是:

(...previous queries that work good locally and on heroku...) (...以前在本地和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. 我的heroku错误是:“ products.id”必须出现在GROUP BY子句中或在聚合函数中使用。

This tells me the error is the GROUP BY and drom the documentation I read that i must put all the columns here. 这告诉我错误是GROUP BY和drom阅读的文档,我必须将所有列放在此处。 But since it is a HABTM relation, only other column is there, and when I put it, the arel spots functioning properly. 但是,由于这是HABTM关系,因此仅存在其他列,而当我将其放置时,这些区域将正常运行。

I know that there are already threads on this but none have fixed my problem. 我知道已经有线程,但是没有一个可以解决我的问题。

Thank you in advance. 先感谢您。

Regards, Miguel A. 此致Miguel A.

This is related to this: 这与此有关:

Heroku (PG::Error: ERROR: column must appear in the GROUP BY clause or be used in an aggregate function Heroku(PG :: Error:ERROR:列必须出现在GROUP BY子句中或在聚合函数中使用

They use an older version of postgres in Heroku that doesn't support what you're trying to do. 他们在Heroku中使用了较旧的postgres版本,该版本不支持您尝试执行的操作。 Using the Heroku Shared PostgreSQL addon can solve the issue. 使用Heroku Shared PostgreSQL插件可以解决此问题。

Although, I would also suggest that your development environment looks as much as possible as the Heroku environment. 虽然,我也建议您的开发环境与Heroku环境尽可能地相似。 This means using same versions of rubies and same DB... 这意味着使用相同版本的红宝石和相同的数据库...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM