Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
288 views
in Technique[技术] by (71.8m points)

ruby on rails - Ankane GroupDate issue with .minimum .maximum

Using this gem https://github.com/ankane/groupdate I'm having issue when using anything else than .count

I have products where I store the price value every few hours in a PriceHistory table. The following query is working (Counting the number of price_histories for each day)

Product.first.price_histories.group_by_day(:created_at, range: 7.days.ago..Time.now).count

But this one is not (I'm trying to get the minimum price for each day)

Product.first.price_histories.group_by_day(:price, range: 7.days.ago..Time.now).minimum

How could I do that with or without the gem ?

Thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The query was not correct it should have been

Product.first.price_histories.group_by_day(:created_at, range: 7.days.ago..Time.now).minimum(:price)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...