{"action":"opened","issue":{"url":"https://api.github.com/repos/rails/rails/issues/31168","repository_url":"https://api.github.com/repos/rails/rails","labels_url":"https://api.github.com/repos/rails/rails/issues/31168/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/31168/comments","events_url":"https://api.github.com/repos/rails/rails/issues/31168/events","html_url":"https://github.com/rails/rails/issues/31168","id":274582941,"number":31168,"title":"ActiveRecord sum returns nil for date time columns","user":{"login":"curtp","id":582067,"avatar_url":"https://avatars3.githubusercontent.com/u/582067?v=4","gravatar_id":"","url":"https://api.github.com/users/curtp","html_url":"https://github.com/curtp","followers_url":"https://api.github.com/users/curtp/followers","following_url":"https://api.github.com/users/curtp/following{/other_user}","gists_url":"https://api.github.com/users/curtp/gists{/gist_id}","starred_url":"https://api.github.com/users/curtp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/curtp/subscriptions","organizations_url":"https://api.github.com/users/curtp/orgs","repos_url":"https://api.github.com/users/curtp/repos","events_url":"https://api.github.com/users/curtp/events{/privacy}","received_events_url":"https://api.github.com/users/curtp/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-11-16T16:39:45Z","updated_at":"2017-11-16T16:39:45Z","closed_at":null,"author_association":"NONE","body":"We've been using the sum method on date time columns for many versions of rails.  We're upgrading from 4.2 to 5.0 (on the way to 5.1) and encountered the following issue.\r\n\r\nIn rails 4.2 (and before) the following would return a value\r\nPostComments.where(post_id: 1).sum(:updated_at)\r\n => 584938820615279  \r\n\r\nIn rails 5.0.6 it is returning nil\r\nPostComments.where(post_id: 1).sum(:updated_at)\r\n => nil\r\n\r\nI tried this and it seemed to work\r\nPostComments.where(post_id: 1).select(\"sum(updated_at) as sum\").first.sum\r\n=> 584938820615279\r\n\r\nRails version: 5.0.6\r\nRuby version: 2.3.0\r\n\r\n"}}
{"actor":{"display_login":"curtp"}}