composite_primary_keys 13.0.5 → 13.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.rdoc +3 -0
- data/lib/composite_primary_keys/associations/preloader/association.rb +19 -11
- data/lib/composite_primary_keys/version.rb +1 -1
- data/test/abstract_unit.rb +1 -1
- data/test/test_bug.rb +45 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0759acf9a94a27e2baafbc5cf15b334f5364b4424120adfcd59a4ed9f783267
|
4
|
+
data.tar.gz: cae92844f0543e33b85b91620d06ab9032cda41c6e9e7ef27bfeec81d1e2027e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85d3dfab843abaf4371da5717d5b0962b281e81e9e3294fd2154571bec87d3e46b6852cc36be0de1c8aebec0f892a74c04e49296409d94d842bd18a0e7380534
|
7
|
+
data.tar.gz: 5d31a6dca9bd32215fcdf42c095eee41d6f6f56aef08c2ebda5dfef5d33686636f631542a029636da0dd7c6565bd48f8f99f606d137db532db9544aaee72b790
|
data/History.rdoc
CHANGED
@@ -33,20 +33,28 @@ module ActiveRecord
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
owners_by_key[
|
46
|
-
(
|
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
|
data/test/abstract_unit.rb
CHANGED
data/test/test_bug.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path('../abstract_unit', __FILE__)
|
2
|
+
|
3
|
+
require "bundler/inline"
|
4
|
+
|
5
|
+
|
6
|
+
require "minitest/autorun"
|
7
|
+
require "logger"
|
8
|
+
|
9
|
+
# This connection will do for database-independent bug reports.
|
10
|
+
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
|
11
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
12
|
+
|
13
|
+
ActiveRecord::Schema.define do
|
14
|
+
create_table :parents, force: true do |t|
|
15
|
+
end
|
16
|
+
|
17
|
+
create_table :children, id: false, force: true do |t|
|
18
|
+
t.bigint :id
|
19
|
+
t.bigint :parent_id
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Parent < ActiveRecord::Base
|
24
|
+
end
|
25
|
+
|
26
|
+
class Child < ActiveRecord::Base
|
27
|
+
belongs_to :parent
|
28
|
+
end
|
29
|
+
|
30
|
+
class BugTest < Minitest::Test
|
31
|
+
def test_association_stuff
|
32
|
+
p1 = Parent.create!
|
33
|
+
p2 = Parent.create!
|
34
|
+
p3 = Parent.create!
|
35
|
+
Child.create!(id: 100, parent_id: p1.id)
|
36
|
+
Child.create!(id: 100, parent_id: p2.id)
|
37
|
+
Child.create!(id: 100, parent_id: p3.id)
|
38
|
+
|
39
|
+
children = Child.preload(:parent)
|
40
|
+
# if uncomment following line, this test pass
|
41
|
+
# children = Child.all
|
42
|
+
parents = children.map(&:parent)
|
43
|
+
assert_equal [p1.id, p2.id, p3.id], parents.map(&:id)
|
44
|
+
end
|
45
|
+
end
|
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.
|
4
|
+
version: 13.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charlie Savage
|
@@ -171,6 +171,7 @@ files:
|
|
171
171
|
- test/test_associations.rb
|
172
172
|
- test/test_attribute_methods.rb
|
173
173
|
- test/test_attributes.rb
|
174
|
+
- test/test_bug.rb
|
174
175
|
- test/test_calculations.rb
|
175
176
|
- test/test_callbacks.rb
|
176
177
|
- test/test_composite_arrays.rb
|
@@ -226,6 +227,7 @@ test_files:
|
|
226
227
|
- test/test_associations.rb
|
227
228
|
- test/test_attribute_methods.rb
|
228
229
|
- test/test_attributes.rb
|
230
|
+
- test/test_bug.rb
|
229
231
|
- test/test_calculations.rb
|
230
232
|
- test/test_callbacks.rb
|
231
233
|
- test/test_composite_arrays.rb
|