Comments (5)
Can you create a reproduction test script using https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_record.rb template?
from rails.
Sure thing, it breaks with sqlite as well. Seems like I cannot attach .rb files here so sry, test is in markdown:
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem "rails", "~> 7.1.0"
gem "sqlite3", "~> 1.4"
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 :item_types, force: true do |t|
t.string :item_type_nm, null: false
end
create_table :items, primary_key: [:item_type_id, :other_field] do |t|
t.string :other_field, null: false
t.references :item_type
end
end
class ItemType < ActiveRecord::Base
has_many :items
end
class Item < ActiveRecord::Base
self.primary_key = [:item_type_id, :other_field]
belongs_to :item_type
end
class BugTest < Minitest::Test
def test_count_with_references
Item.where(item_type_nm: 'a').includes(:item_type).references(:item_type).count
end
end
from rails.
PS: .where condition is not actually relevant when reproducing the bug
from rails.
PS2: it seems to boil down to
lib/active_record/relation/calculations.rb
where
def select_for_count
if select_values.present? # select_values here is assigned from table.primary_key i.e. [[:col1, :col2]]
return select_values.first if select_values.one? # returns [:col1, :col2]
select_values.join(", ")
...
end
from rails.
I was able to identify the problem and seems like found the solution. Will open a PR a bit later today.
But you are welcome to open a PR, if you want to try to fix it by yourself.
from rails.
Related Issues (20)
- Should select show a prompt when its attribute is false? HOT 8
- collection_check_boxes hidden field ignores :form option
- Action Cable as Stand Alone server leads to Devise::MissingWarden: error HOT 2
- Postgres prepared statements and array queries with certain syntax result in `PG::InvalidTextRepresentation` HOT 5
- Rubocop binstubs issue causes failures on Windows
- [ActiveRecord] Enum defined methods does not follow naming convention HOT 5
- `ActiveRecord::ConnectionAdapters::SQLite3Adapter#initialize` does not correctly create missing parent directories HOT 6
- `Object.as_json` is too optimistic and causes errors in 3rd party code. HOT 4
- `ActiveSupport::Inflector` isolation/conflicts: recommended approach HOT 4
- Individually uncommenting `ActiveRecord` related framework defaults, not enabling respective behaviour HOT 3
- Remove trailing slash from void HTML elements HOT 2
- It is not possible to pass raw JSON string to ActiveRecord JSON type attribute HOT 1
- undefined method `path' for class Selenium::WebDriver::DriverFinder (NoMethodError) with selenium-webdriver 4.20.0 HOT 4
- Need a Rails Guide on Dynamic Forms with Hotwire HOT 1
- Truncate tables before test runs is hanging on Linux
- Inconsistent documentation between ActiveRecord::RecordNotSaved and ActiveRecord::Persistence::ClassMethods#save!
- Prevent fork bombs in ActiveSupport::ForkTracker HOT 1
- Avoid Seed Data Execution in CI by Replacing `db:setup` with `db:test:prepare` HOT 3
- ActiveRecord time field issue with timezone HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rails.