Giter VIP home page Giter VIP logo

rails's People

Contributors

amatsuda avatar arunagw avatar carlosantoniodasilva avatar dhh avatar drogus avatar eileencodes avatar fxn avatar guilleiguaran avatar jeremy avatar jonleighton avatar josevalim avatar josh avatar kamipo avatar kaspth avatar lifo avatar maclover7 avatar matthewd avatar miloops avatar nzkoz avatar pixeltrix avatar prathamesh-sonpatki avatar rafaelfranca avatar senny avatar sgrif avatar spastorino avatar technoweenie avatar tenderlove avatar vijaydev avatar vipulnsward avatar y-yagi avatar

Watchers

 avatar  avatar

rails's Issues

Active Record GROUP_BY/COUNT calculation returns incorrect result

Steps to reproduce

Is this intentional?

# frozen_string_literal: true

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  # Activate the gem you are reporting the issue against.
  gem "activerecord", "~> 7.0.0"
  gem "sqlite3"
end

require "active_record"
require "minitest/autorun"
require "logger"

# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = Logger.new(STDOUT)

ActiveRecord::Schema.define do
  # テーブル定義
  create_table :evaluation_template_role_scene_item_restrictions, force: true do |t|
    t.bigint :evaluation_template_sheet_item_id, null: false
    t.bigint :evaluation_template_role_scene_restriction_id, null: false
    t.timestamps
  end
end

module EvaluationTemplate
  module Role
    class SceneItemRestriction < ActiveRecord::Base
      self.table_name = 'evaluation_template_role_scene_item_restrictions'
    end
  end
end

class BugTest < Minitest::Test
  def test_association_stuff
    2.times do
      EvaluationTemplate::Role::SceneItemRestriction.create!(
        evaluation_template_role_scene_restriction_id: 1,
        evaluation_template_sheet_item_id: 2
      )
    end

    res = EvaluationTemplate::Role::SceneItemRestriction.group(:evaluation_template_role_scene_restriction_id, :evaluation_template_sheet_item_id).having("count(*) >= 2").count

    # ここが期待通り動かない
    assert_equal({ [1, 2] => 2 }, res)
  end
end

Expected behavior

It should return expected count grouping by 2 columns.

{[1, 2]=>2}

Actual behavior

{[2, 2]=>2}

System configuration

Rails version: gem "activerecord", "~> 7.0.0"

Ruby version: ruby 3.0.2p107

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.