Created
September 15, 2016 21:24
-
-
Save kpheasey/a6e2b305cfa9e41ae2be9a792219700c to your computer and use it in GitHub Desktop.
Speed Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Order < ApplicationRecord | |
belongs_to :customer | |
def totals_by_customer | |
Order.all.pluck(:customer).distinct.map do |customer| | |
[customer, customer.orders.sum(:total))] | |
end | |
end | |
end | |
class Customer < ApplicationRecord | |
has_many :orders | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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