Closed github0013 closed 3 years ago
# == Schema Information # # Table name: products # # id :bigint not null, primary key # quantity :integer not null # created_at :datetime not null # updated_at :datetime not null # class Product < ApplicationRecord acts_as_taggable end Product.destroy_all Product.create!(quantity: 1) Product.sum(:quantity) # => 1 Product.includes(:tags).sum(:quantity) # => 1 Product.group(:id).sum(:quantity) # => {1 => 1} Product.includes(:tags).group(:id).sum(:quantity) # => {1 => 1} Product.destroy_all Product.create!(quantity: 1, tag_list: %w[a b c]) Product.sum(:quantity) # => 1 Product.includes(:tags).sum(:quantity) # => 3 !!!! Product.group(:id).sum(:quantity) # => {2 => 1} Product.includes(:tags).group(:id).sum(:quantity) # => {2 => 3} !!!!
Product.destroy_all Product.create!(quantity: 1, tag_list: %w[a b c]) Product.includes(:tags).sum(:quantity) # => this should give 1
Product.destroy_all Product.create!(quantity: 1, tag_list: %w[a b c]) Product.includes(:tags).sum(:quantity) # => 3, instead of 1
Environments
Reproduction
Expected
Actual