1

I was advised to create a new question based on my previous one so here it is :

I have on my website a list of product, each user can create his own savings based on these products. So several users can create their own savings based on the same product. So when one user create a saving I add in the database a saving with the user_id and the product_id he refers to. Now, on one page I want to display all the savings from the other users (excluding current_user) but, as many user can create a saving based on the same product I want to display these only once.If several users create a saving based on product X I want it only displayed once,thanks

The saving table has these field :

id product_id user_id price saved

What I did is what is posted on this question : Squeel request and Heroku, Postgres: Error using GROUP BY and ORDER

I cannot get it working properly on heroku (postgres). If anyone can help me writing the query for Rails or for Squeel that would be awesome thanks !

4

1 回答 1

1

好吧,克雷格感谢您的帮助,我最终做到了,它正在本地开发 PG!

Saving.select("DISTINCT ON (savings.product_id) * ").where{product_id.not_in(current_user_savings.select{product_id})}.group("savings.user_id, savings.updated_at, savings.id, savings.product_id, savings.price,savings.wishlist_id, savings.saved, savings.created_at")

遇到这个问题让我在 dev 中将我的 db 从 mysql 切换到 pg,所以在 heroku 中不再感到惊讶!

于 2012-11-01T10:40:55.717 回答