counter_culture 3.11.3 → 3.11.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75ac99d8d45f3e16859bb04854958dac048a449aa4afe94f12885cefe3a94787
4
- data.tar.gz: e90d1b87ea3e2d919434dbeea2263fa5556044dc273cab21a6a67b423519c012
3
+ metadata.gz: 4978dfaab9ec73c8b3215c2d2f811093cc00cdf7daccfe877749f301a09ae11a
4
+ data.tar.gz: e2e1322882fdeab8c7239c7cf16e4019b5450d3f435c478ad1d9e2d33cf5a251
5
5
  SHA512:
6
- metadata.gz: dc1196535a528c5f87e39aca06d5e1a3e014f469c8aa3e8f01c56f75a59489c4db25dc9b67168b162ddf9ac24e45c55fe887c10176e76786dea5ffe72603f10b
7
- data.tar.gz: a949a3856773028e954e00c8ce5ba89ac0e999230c47af3d1b0e312fdef827cbbf0dc71ed91406c6b2b77ba4d194b108f21df8b904f0e09592d2b5ef2a0e25d9
6
+ metadata.gz: a60b46c8b713dbbb7f2969c9b6885e9975a1c5723eb3566a04b011380eafb077c3051386586cff7c77b5ba171888ef577aa5d1dd6be4a4d97ea8e1db1fdca91d
7
+ data.tar.gz: 51feccb08cf927e8fc6f1d41f39f91269411db70d96d3b44d57ddf35c67130790c1340cb27aff0e0f4701934b40bc17485345667d1bffcbfb145eb4a5d98bea6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 3.11.4 (November 5, 2025)
2
+
3
+ Bugfixes:
4
+ - Fix counter cache not using the correct type with multiple STI models in the association chain (#421)
5
+
1
6
  ## 3.11.3 (October 22, 2025)
2
7
 
3
8
  Bugfixes:
@@ -240,11 +240,11 @@ module CounterCulture
240
240
  Array.wrap(primary_key).map { |pk| value.try(pk&.to_sym) }.compact.presence
241
241
  end
242
242
 
243
- # gets the reflect object on the given relation
243
+ # gets the reflect object on the given relation and the model that defines this reflect
244
244
  #
245
245
  # relation: a symbol or array of symbols; specifies the relation
246
246
  # that has the counter cache column
247
- def relation_reflect(relation)
247
+ def relation_reflect_and_model(relation)
248
248
  relation = relation.is_a?(Enumerable) ? relation.dup : [relation]
249
249
 
250
250
  # go from one relation to the next until we hit the last reflect object
@@ -262,7 +262,16 @@ module CounterCulture
262
262
  end
263
263
  end
264
264
 
265
- return reflect
265
+ return [reflect, klass]
266
+ end
267
+
268
+
269
+ # gets the reflect object on the given relation
270
+ #
271
+ # relation: a symbol or array of symbols; specifies the relation
272
+ # that has the counter cache column
273
+ def relation_reflect(relation)
274
+ relation_reflect_and_model(relation).first
266
275
  end
267
276
 
268
277
  # gets the class of the given relation
@@ -59,7 +59,7 @@ module CounterCulture
59
59
  class Reconciliation
60
60
  attr_reader :counter, :options, :relation_class
61
61
 
62
- delegate :model, :relation, :full_primary_key, :relation_reflect, :polymorphic?, :to => :counter
62
+ delegate :model, :relation, :full_primary_key, :relation_reflect_and_model, :relation_reflect, :polymorphic?, :to => :counter
63
63
  delegate *CounterCulture::Counter::CONFIG_OPTIONS, :to => :counter
64
64
 
65
65
  def initialize(counter, changes_holder, options, relation_class)
@@ -257,11 +257,11 @@ module CounterCulture
257
257
  # store joins in an array so that we can later apply column-specific
258
258
  # conditions
259
259
  join_clauses = reverse_relation.each_with_index.map do |cur_relation, index|
260
- reflect = relation_reflect(cur_relation)
260
+ reflect, model = relation_reflect_and_model(cur_relation)
261
261
 
262
- target_table = quote_table_name(reflect.active_record.table_name)
262
+ target_table = quote_table_name(model.table_name)
263
263
  target_table_alias = parameterize(target_table)
264
- if relation_class.table_name == reflect.active_record.table_name
264
+ if relation_class.table_name == model.table_name
265
265
  # join with alias to avoid ambiguous table name in
266
266
  # self-referential models
267
267
  target_table_alias += "_#{target_table_alias}"
@@ -299,8 +299,8 @@ module CounterCulture
299
299
 
300
300
  # adds 'type' condition to JOIN clause if the current model is a
301
301
  # child in a Single Table Inheritance
302
- if reflect.active_record.column_names.include?('type') &&
303
- !model.descends_from_active_record?
302
+ if model.column_names.include?('type') &&
303
+ !model.descends_from_active_record?
304
304
  joins_sql += " AND #{target_table_alias}.type IN ('#{model.name}')"
305
305
  end
306
306
  if polymorphic?
@@ -1,3 +1,3 @@
1
1
  module CounterCulture
2
- VERSION = '3.11.3'.freeze
2
+ VERSION = '3.11.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: counter_culture
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.11.3
4
+ version: 3.11.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Magnus von Koeller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-10-23 00:00:00.000000000 Z
11
+ date: 2025-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord