# What is the difference between model.sum(&:column) and model.sum(:column)?

**URL:** <https://discuss.rubyonrails.org/t/what-is-the-difference-between-model-sum-column-and-model-sum-column/83220>\
**Category:** rubyonrails-talk\
**Created:** [July 10, 2023, 9:59pm UTC](https://discuss.rubyonrails.org/t/what-is-the-difference-between-model-sum-column-and-model-sum-column/83220 "2023-07-10T21:59:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ww9](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/ww9/32/9966_2.png) [@ww9](https://discuss.rubyonrails.org/u/ww9)\
**Post date:** [July 10, 2023, 9:59pm UTC](https://discuss.rubyonrails.org/t/what-is-the-difference-between-model-sum-column-and-model-sum-column/83220/1 "2023-07-10T21:59:02Z")

</div>

Hi! Newbie question so pleae bear with me.

What is the difference between **model.sum(&:column)** and **model.sum(:column)**?

I ask because I saw this code

![Image](https://global.discourse-cdn.com/rubyonrails/original/2X/7/77ad33233b4d1724b3909dec4c0ed97f729852a4.png)

In a redmine (rails) plugin.

---

<div class="post-metadata">

**Author:** ![brenogazzola](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/brenogazzola/32/3856_2.png) [@brenogazzola](https://discuss.rubyonrails.org/u/brenogazzola)\
**Post date:** [July 12, 2023, 5:03pm UTC](https://discuss.rubyonrails.org/t/what-is-the-difference-between-model-sum-column-and-model-sum-column/83220/2 "2023-07-12T17:03:54Z")

</div>

First one is a Rails method that will be converted into a SQL query and return the sum. Second one is a Ruby method that cause Rails to load every order\_item in memory, pass them to Ruby to do the sum.

Take a look at the query log and the difference will be obvious:

```ruby
> Order.where(paid_at: Date.current..).sum(:item_total)
# DEBUG -- : Order Sum SELECT SUM("orders"."item_total") FROM "orders" WHERE "orders"."paid_at" >= $1 [["paid_at", "2023-07-12"]]

> Order.where(paid_at: Date.current..).sum(&:item_total)
# DEBUG -- : Order Load SELECT "orders".* FROM "orders" WHERE "orders"."paid_at" >= $1 [["paid_at", "2023-07-12"]]

```

TL:DR: If you have not accessed `ib_service_order_items` before in your code, `(:total_usts)` will be faster (no need to load every item in memory before summing). If you have accessed `ib_service_order_items` before in your code, `(&:total_usts)` will be faster (not need for the extra query, just use the objects in memory.

---

<div class="post-metadata">

**Author:** ![ww9](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/ww9/32/9966_2.png) [@ww9](https://discuss.rubyonrails.org/u/ww9)\
**Post date:** [July 13, 2023, 1:53pm UTC](https://discuss.rubyonrails.org/t/what-is-the-difference-between-model-sum-column-and-model-sum-column/83220/4 "2023-07-13T13:53:19Z")

</div>

That was quite clear! Thanks!
