composite_primary_keys 7.0.7 → 7.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.rdoc +9 -0
- data/lib/composite_primary_keys/associations/join_dependency.rb +33 -38
- data/lib/composite_primary_keys/version.rb +1 -1
- data/test/test_find.rb +0 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc0ec64847be066d4ea0a2e1cc8bbef8d938df03
|
4
|
+
data.tar.gz: 27a854255a8c832b24ada64d40d056611d147b35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83dfb994708e614f2379506ae3282fcc3bd104ee29f37aadfb98bab8bfac019a9c9c8dd9376dd774c61e24da632296f1d7af8b8b5ada38bbbbe53f35870ed2fc
|
7
|
+
data.tar.gz: 688a266a56600582a2853dd913684266953e17bd591a89594f903c12cfeaa181fe0832717fa33f961f47e74d96cd512d982700e27ecd9184d7eb314c999647db
|
data/History.rdoc
CHANGED
@@ -1,9 +1,18 @@
|
|
1
|
+
== 7.0.8 (2014-08-03)
|
2
|
+
|
3
|
+
* Fix instantiation of has_many records via :includes that use composite keys (Charlie Savage)
|
4
|
+
|
1
5
|
== 7.0.7 (2014-07-29)
|
2
6
|
|
3
7
|
* Add back support for calling find like this (Sammy Larbi):
|
4
8
|
|
5
9
|
Membership.find('1,1')
|
6
10
|
|
11
|
+
== 7.0.7 (2014-07-29)
|
12
|
+
|
13
|
+
* Add back support for calling find like this (Sammy Larbi):
|
14
|
+
|
15
|
+
Membership.find('1,1')
|
7
16
|
|
8
17
|
== 7.0.6 (2014-07-22)
|
9
18
|
|
@@ -33,10 +33,10 @@ module ActiveRecord
|
|
33
33
|
# CPK
|
34
34
|
#primary_id = type_caster.type_cast row_hash[primary_key]
|
35
35
|
primary_id = if primary_key.kind_of?(Array)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
primary_key.map {|key| type_caster.type_cast row_hash[key]}
|
37
|
+
else
|
38
|
+
type_caster.type_cast row_hash[primary_key]
|
39
|
+
end
|
40
40
|
parent = parents[primary_id] ||= join_root.instantiate(row_hash, column_aliases)
|
41
41
|
construct(parent, join_root, row_hash, result_set, seen, model_cache, aliases)
|
42
42
|
}
|
@@ -44,49 +44,44 @@ module ActiveRecord
|
|
44
44
|
parents.values
|
45
45
|
end
|
46
46
|
|
47
|
-
|
47
|
+
def construct(ar_parent, parent, row, rs, seen, model_cache, aliases)
|
48
|
+
primary_id = ar_parent.id
|
48
49
|
|
49
|
-
|
50
|
-
|
50
|
+
parent.children.each do |node|
|
51
|
+
if node.reflection.collection?
|
52
|
+
other = ar_parent.association(node.reflection.name)
|
53
|
+
other.loaded!
|
54
|
+
else
|
55
|
+
if ar_parent.association_cache.key?(node.reflection.name)
|
56
|
+
model = ar_parent.association(node.reflection.name).target
|
57
|
+
construct(model, node, row, rs, seen, model_cache, aliases)
|
58
|
+
next
|
59
|
+
end
|
60
|
+
end
|
51
61
|
|
52
|
-
|
53
|
-
if macro == :has_one
|
54
|
-
return if record.association_cache.key?(join_part.reflection.name)
|
55
|
-
# CPK
|
56
|
-
# association = join_part.instantiate(row) unless row[join_part.aliased_primary_key].nil?
|
57
|
-
association = association_for_primary_key_from_row(join_part, row)
|
62
|
+
key = aliases.column_alias(node, node.primary_key)
|
58
63
|
|
59
|
-
set_target_and_inverse(join_part, association, record)
|
60
|
-
else
|
61
64
|
# CPK
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
other = record.association(join_part.reflection.name)
|
68
|
-
other.loaded!
|
69
|
-
other.target.push(association) if association
|
70
|
-
other.set_inverse_instance(association)
|
71
|
-
when :belongs_to
|
72
|
-
set_target_and_inverse(join_part, association, record)
|
65
|
+
if key.is_a?(Array)
|
66
|
+
id = Array(key).map do |column_alias|
|
67
|
+
row[column_alias]
|
68
|
+
end
|
69
|
+
next if id.empty?
|
73
70
|
else
|
74
|
-
|
71
|
+
id = row[key]
|
72
|
+
next if id.nil?
|
75
73
|
end
|
76
|
-
end
|
77
|
-
association
|
78
|
-
end
|
79
74
|
|
80
|
-
|
75
|
+
model = seen[parent.base_klass][primary_id][node.base_klass][id]
|
81
76
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
77
|
+
if model
|
78
|
+
construct(model, node, row, rs, seen, model_cache, aliases)
|
79
|
+
else
|
80
|
+
model = construct_model(ar_parent, node, row, model_cache, id, aliases)
|
81
|
+
seen[parent.base_klass][primary_id][node.base_klass][id] = model
|
82
|
+
construct(model, node, row, rs, seen, model_cache, aliases)
|
83
|
+
end
|
88
84
|
end
|
89
|
-
result
|
90
85
|
end
|
91
86
|
end
|
92
87
|
end
|
data/test/test_find.rb
CHANGED
@@ -20,10 +20,6 @@ class TestFind < ActiveSupport::TestCase
|
|
20
20
|
ref_code = ReferenceCode.find([1,3])
|
21
21
|
assert_not_nil(ref_code)
|
22
22
|
assert_equal([1,3], ref_code.id)
|
23
|
-
|
24
|
-
ref_code = ReferenceCode.find(1,3)
|
25
|
-
assert_not_nil(ref_code)
|
26
|
-
assert_equal([1,3], ref_code.id)
|
27
23
|
end
|
28
24
|
|
29
25
|
def test_find_some
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: composite_primary_keys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.0.
|
4
|
+
version: 7.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charlie Savage
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -214,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
214
|
version: '0'
|
215
215
|
requirements: []
|
216
216
|
rubyforge_project:
|
217
|
-
rubygems_version: 2.
|
217
|
+
rubygems_version: 2.4.1
|
218
218
|
signing_key:
|
219
219
|
specification_version: 4
|
220
220
|
summary: Composite key support for ActiveRecord
|