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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df048b0184c228678c8e77400bc92ec63f54c008
4
- data.tar.gz: 01f520e6e90a9216c0d76e2174703ae9a2f0edbb
3
+ metadata.gz: cc0ec64847be066d4ea0a2e1cc8bbef8d938df03
4
+ data.tar.gz: 27a854255a8c832b24ada64d40d056611d147b35
5
5
  SHA512:
6
- metadata.gz: db16567e55619423e804aeaed7f094d133af909875ad09ed59b8e52da55bae3e3aaeecf710cffc88423ed41dc90a4c31e43492ab8981c6088279c7b8b472a8e8
7
- data.tar.gz: f526cdb914772be1e606fd7ec496829b29ed5682a29cbbddf19f19bd4cc6606f621726d7571a71df9ecf436a06392a148db878621576a086690e14eadbd2889c
6
+ metadata.gz: 83dfb994708e614f2379506ae3282fcc3bd104ee29f37aadfb98bab8bfac019a9c9c8dd9376dd774c61e24da632296f1d7af8b8b5ada38bbbbe53f35870ed2fc
7
+ data.tar.gz: 688a266a56600582a2853dd913684266953e17bd591a89594f903c12cfeaa181fe0832717fa33f961f47e74d96cd512d982700e27ecd9184d7eb314c999647db
@@ -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
- primary_key.map {|key| type_caster.type_cast row_hash[key]}
37
- else
38
- type_caster.type_cast row_hash[primary_key]
39
- end
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
- protected
47
+ def construct(ar_parent, parent, row, rs, seen, model_cache, aliases)
48
+ primary_id = ar_parent.id
48
49
 
49
- def construct_association(record, join_part, row)
50
- return if record.id.to_s != join_part.parent.record_id(row).to_s
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
- macro = join_part.reflection.macro
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
- # association = join_part.instantiate(row) unless row[join_part.aliased_primary_key].nil?
63
- association = association_for_primary_key_from_row(join_part, row)
64
-
65
- case macro
66
- when :has_many, :has_and_belongs_to_many
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
- raise ConfigurationError, "unknown macro: #{join_part.reflection.macro}"
71
+ id = row[key]
72
+ next if id.nil?
75
73
  end
76
- end
77
- association
78
- end
79
74
 
80
- private
75
+ model = seen[parent.base_klass][primary_id][node.base_klass][id]
81
76
 
82
- def association_for_primary_key_from_row(join_part, row)
83
- result = nil
84
- if (cpk = join_part.aliased_primary_key).is_a?(Array)
85
- result = join_part.instantiate(row) if cpk.detect {|pk| row[pk].nil? }.nil?
86
- else
87
- result = join_part.instantiate(row) unless row[join_part.aliased_primary_key].nil?
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
@@ -2,7 +2,7 @@ module CompositePrimaryKeys
2
2
  module VERSION
3
3
  MAJOR = 7
4
4
  MINOR = 0
5
- TINY = 7
5
+ TINY = 8
6
6
  STRING = [MAJOR, MINOR, TINY].join('.')
7
7
  end
8
8
  end
@@ -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.7
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-07-29 00:00:00.000000000 Z
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.2.2
217
+ rubygems_version: 2.4.1
218
218
  signing_key:
219
219
  specification_version: 4
220
220
  summary: Composite key support for ActiveRecord