composite_primary_keys 13.0.5 → 13.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 397760c82733f99fafe1596036951df80ad7c440f6b6a8a4362e65459d2a5be9
4
- data.tar.gz: 79b3579f453a63fa55f0474ca5f941d85e647714e9fdd892ca441eb500ad21e2
3
+ metadata.gz: e705c71e8e7a1f2d4aee39d46ba133177960963c2d126ee41caea675ad743dfe
4
+ data.tar.gz: 266bba1595212c20101e3052cc2a24de8654ce817412b82cfbacee6cf3044c56
5
5
  SHA512:
6
- metadata.gz: c4dfc8b13e54c9d4d7e761f545aacc262ad569681593175f29cf53040cfbd6ebf4a5d24b4e2698b0d6a90eb703650ce983f25410ca2cb8706d5776bcfa1c27a9
7
- data.tar.gz: a7e17419407f1621c17c523594d80281dbbb1d16acde923678fd847d2d386c611f13d4b40a0e35c2532f22a8f63a7bdc888e5bfd3a258ece8f7e52c5a50bf61d
6
+ metadata.gz: 80a8ad394e2393f3fbae332a9ba5d8db8bea4484b09834e5ef0749395b188e796e13cab5625688530e4f299464400e2cf0dc67a37f6a27160890cbe08ae8857d
7
+ data.tar.gz: 48a459a2296938f41a40e98e8f533ae0d7ee8bcd427406dd05af4a1a697466c19e1ba4d4c2212b7d4518e1308ef528ec83f1d52b5b59808016c65d8314c3f074
data/History.rdoc CHANGED
@@ -1,3 +1,9 @@
1
+ == 13.0.7 (2023-02-04)
2
+ * Fix #573 (Charlie Savage)
3
+
4
+ == 13.0.6 (2023-02-04)
5
+ * Fix #577 (Charlie Savage)
6
+
1
7
  == 13.0.5 (2023-02-04)
2
8
  * Improve query generation for cpk_in_predicate. This reduces the length of
3
9
  queries when loading many keys and enables Postgres to use index scans
@@ -33,20 +33,28 @@ module ActiveRecord
33
33
  end
34
34
  end
35
35
 
36
- def records_by_owner
37
- @records_by_owner ||= preloaded_records.each_with_object({}) do |record, result|
38
- key = if association_key_name.is_a?(Array)
39
- Array(record[association_key_name]).map do |key|
40
- convert_key(key)
41
- end
42
- else
43
- convert_key(record[association_key_name])
44
- end
45
- owners_by_key[key].each do |owner|
46
- (result[owner] ||= []) << record
36
+ def load_records
37
+ # owners can be duplicated when a relation has a collection association join
38
+ # #compare_by_identity makes such owners different hash keys
39
+ @records_by_owner = {}.compare_by_identity
40
+ raw_records = owner_keys.empty? ? [] : records_for(owner_keys)
41
+
42
+ @preloaded_records = raw_records.select do |record|
43
+ assignments = false
44
+
45
+ owners_by_key[convert_key(record[association_key_name])].each do |owner|
46
+ entries = (@records_by_owner[owner] ||= [])
47
+
48
+ if reflection.collection? || entries.empty?
49
+ entries << record
50
+ assignments = true
51
+ end
47
52
  end
53
+
54
+ assignments
48
55
  end
49
56
  end
57
+
50
58
  end
51
59
  end
52
60
  end
@@ -29,7 +29,7 @@ module ActiveRecord
29
29
  stmt.key = table[primary_key]
30
30
 
31
31
  # CPK
32
- if @klass.composite? && @klass.connection.visitor.compile(stmt.ast) =~ /['"]#{primary_key.to_s}['"]/
32
+ if @klass.composite?
33
33
  stmt = Arel::UpdateManager.new
34
34
  stmt.table(arel_table)
35
35
  cpk_subquery(stmt)
@@ -74,7 +74,7 @@ module ActiveRecord
74
74
  stmt.key = table[primary_key]
75
75
 
76
76
  # CPK
77
- if @klass.composite? && @klass.connection.visitor.compile(stmt.ast) =~ /['"]#{primary_key.to_s}['"]/
77
+ if @klass.composite?
78
78
  stmt = Arel::DeleteManager.new
79
79
  stmt.from(arel_table)
80
80
  cpk_subquery(stmt)
@@ -2,7 +2,7 @@ module CompositePrimaryKeys
2
2
  module VERSION
3
3
  MAJOR = 13
4
4
  MINOR = 0
5
- TINY = 5
5
+ TINY = 7
6
6
  STRING = [MAJOR, MINOR, TINY].join('.')
7
7
  end
8
8
  end
@@ -1,4 +1,4 @@
1
- spec_name = ENV['ADAPTER'] || 'sqlite'
1
+ spec_name = ENV['ADAPTER'] || 'postgresql'
2
2
  require 'bundler'
3
3
  require 'minitest/autorun'
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: composite_primary_keys
3
3
  version: !ruby/object:Gem::Version
4
- version: 13.0.5
4
+ version: 13.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charlie Savage