You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# frozen_string_literal: true
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem "rails", github: "rails/rails"
gem "arel", github: "rails/arel"
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 :journals, force: true do |t|
t.integer :issues_count, default: 0
t.integer :articles_count, default: 0
end
create_table :issues, force: true do |t|
t.integer :journal_id
t.integer :articles_count
end
create_table :articles, force: true do |t|
t.integer :issue_id
end
end
class Journal < ActiveRecord::Base
has_many :issues
has_many :articles, through: :issues
end
class Issue < ActiveRecord::Base
belongs_to :journal, counter_cache: true
has_many :articles
end
class Article < ActiveRecord::Base
belongs_to :issue, counter_cache: true
end
class BugTest < Minitest::Test
def test_counter_cache
journal = Journal.create!
journal.issues << Issue.create!(articles: [Article.create!, Article.create!])
Journal.reset_counters(journal.id, :articles)
assert_equal journal.reload.articles_count, 2
end
end
Expected behavior
Counter articles_count will be updated
Actual behavior
Instead of articles_count counter column, call of #reset_counters updates issues_count counter column
System configuration
Rails version: master
Ruby version: 2.4.0
The text was updated successfully, but these errors were encountered:
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 5-1-stable branch or on master, please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.
Steps to reproduce
Expected behavior
Counter
articles_count
will be updatedActual behavior
Instead of
articles_count
counter column, call of #reset_counters updatesissues_count
counter columnSystem configuration
Rails version: master
Ruby version: 2.4.0
The text was updated successfully, but these errors were encountered: