Skip to content

Instantly share code, notes, and snippets.

@elrok123
Created May 12, 2013 14:27
Show Gist options
  • Save elrok123/5563757 to your computer and use it in GitHub Desktop.
Save elrok123/5563757 to your computer and use it in GitHub Desktop.
Double save sum error weirdness
irb(main):023:0> order.save
(0.1ms) BEGIN
(0.2ms) SELECT SUM(`products`.`product_price`) AS sum_id FROM `products` INNER JOIN `orderedproducts` ON `products`.`id` = `orderedproducts`.`product_id` WHERE `orderedproducts`.`order_id` IS NULL
SQL (0.1ms) INSERT INTO `orders` (`client_id`, `created_at`, `delivery_date`, `order_total`, `updated_at`) VALUES (1, '2013-05-12 14:25:21', '2013-07-24', 0.0, '2013-05-12 14:25:21')
SQL (0.1ms) INSERT INTO `orderedproducts` (`created_at`, `order_id`, `product_id`, `quantity_ordered`, `updated_at`) VALUES ('2013-05-12 14:25:21', 6, 1, NULL, '2013-05-12 14:25:21')
SQL (0.1ms) INSERT INTO `orderedproducts` (`created_at`, `order_id`, `product_id`, `quantity_ordered`, `updated_at`) VALUES ('2013-05-12 14:25:21', 6, 2, NULL, '2013-05-12 14:25:21')
(47.8ms) COMMIT
=> true
irb(main):024:0> order.save
(0.1ms) BEGIN
(0.3ms) SELECT SUM(`products`.`product_price`) AS sum_id FROM `products` INNER JOIN `orderedproducts` ON `products`.`id` = `orderedproducts`.`product_id` WHERE `orderedproducts`.`order_id` = 6
(0.1ms) UPDATE `orders` SET `order_total` = 20025.9607028961, `updated_at` = '2013-05-12 14:26:52' WHERE `orders`.`id` = 6
(154.0ms) COMMIT
=> true
irb(main):025:0>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment