LoginSignup
1
2

More than 5 years have passed since last update.

ActiveRecordの#sumと#select(sum(..))の違い

Posted at
Hoge.group(:foo).sum(:bar)
# { foo => (barの合計) } という形のhashが返る
Hoge.group(:foo).select("foo, sum(bar)")
# Hogeクラスが返る

上だとHashなのでlimitやorderが使えないが下だとlimitやorderが使える

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2