Skip to content

Instantly share code, notes, and snippets.

@mksm
Forked from kpheasey/models.rb
Last active September 16, 2016 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mksm/b681c5e1ff755c525d9fdbed10a4eed8 to your computer and use it in GitHub Desktop.
Save mksm/b681c5e1ff755c525d9fdbed10a4eed8 to your computer and use it in GitHub Desktop.
Speed Test
class Order < ApplicationRecord
belongs_to :customer
def totals_by_customer
Order.group(:customer).sum(:total)
end
end
class Customer < ApplicationRecord
has_many :orders
end
CREATE TABLE `orders` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`customer_id` int(11) DEFAULT NULL,
`total` int(11) DEFAULT NULL,
);
CREATE TABLE `customers` (
`id` int(11) NOT NULL AUTO_INCREMENT
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment