jsonapi_compliable 0.11.26 → 0.11.27

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: 63d6810b917de89c84b683301cd42dbb0d88a6ae
4
- data.tar.gz: 13312ec071a1764665f701020898e856e45f0825
3
+ metadata.gz: fd319c54a4ba9b170f855b7fa6096fba621d9899
4
+ data.tar.gz: 3f114d62e1af153fb8b0a54075a4974673103e2c
5
5
  SHA512:
6
- metadata.gz: 52f9e04896faeeaab2a0e6e4661a2e69568c25c2c484d824b8df6a217c1c467676c3c99584e92196d3996a32df816b43b3eafdb8d8cd4004236f67b0d6191583
7
- data.tar.gz: 2650a80b254d475ba962af09c9cfa7105f156340df388313b6fa6c55df1859f9bc47d5e29eded38dfdd12bafd1bae2c5b88d77d94617cd526245607e910e2adb
6
+ metadata.gz: d1c1992697517db3a0fbf36595d501672bddb1f33b5355c29a480118db270f0591d9573202f0ec8104e3e5e2106877c9b271e11854b049a4af749aed33447082
7
+ data.tar.gz: a79ab173ff26b5a5eb17cffc9b50da7ae2164012cc7bc96d0c4cacdb35638bdb5dd0a9ba16307b60bd3262bdb0a3f2dff7b130fc3be7c8982ea4632918635ffe
@@ -11,9 +11,10 @@ module JsonapiCompliable
11
11
  end
12
12
 
13
13
  assign do |parents, children|
14
+ children_hash = children.group_by(&foreign_key)
14
15
  parents.each do |parent|
15
16
  parent.association(association_name).loaded!
16
- relevant_children = children.select { |c| c.send(foreign_key) == parent.send(primary_key) }
17
+ relevant_children = children_hash[parent.send(primary_key)] || []
17
18
  relevant_children.each do |c|
18
19
  parent.association(association_name).add_to_target(c, :skip_callbacks)
19
20
  end
@@ -34,8 +35,9 @@ module JsonapiCompliable
34
35
  end
35
36
 
36
37
  assign do |parents, children|
38
+ children_hash = children.index_by(&primary_key)
37
39
  parents.each do |parent|
38
- relevant_child = children.find { |c| parent.send(foreign_key) == c.send(primary_key) }
40
+ relevant_child = children_hash[parent.send(foreign_key)]
39
41
  parent.send(:"#{association_name}=", relevant_child)
40
42
  end
41
43
  end
@@ -62,10 +64,12 @@ module JsonapiCompliable
62
64
  # remove anything else. This is more or less what AR does.
63
65
  assign do |parents, children|
64
66
  assigned = []
67
+ children_hash = children.group_by(&foreign_key)
65
68
  parents.each do |parent|
66
69
  parent.association(association_name).loaded!
67
- relevant_child = children.find { |c| c.send(foreign_key) == parent.send(primary_key) }
68
- next unless relevant_child
70
+ relevant_children = children_hash[parent.send(primary_key)]
71
+ next unless relevant_children
72
+ relevant_child = relevant_children.first
69
73
 
70
74
  # Use private methods because of Rails bug
71
75
  # https://github.com/rails/rails/issues/32886
@@ -75,9 +79,7 @@ module JsonapiCompliable
75
79
  association.send(:target=, relevant_child)
76
80
  assigned << relevant_child
77
81
  end
78
- (children - assigned).each do |unassigned|
79
- children.delete(unassigned)
80
- end
82
+ children.replace(assigned)
81
83
  end
82
84
 
83
85
  instance_eval(&blk) if blk
@@ -1,3 +1,3 @@
1
1
  module JsonapiCompliable
2
- VERSION = "0.11.26"
2
+ VERSION = "0.11.27"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi_compliable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.26
4
+ version: 0.11.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-08-23 00:00:00.000000000 Z
12
+ date: 2018-08-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jsonapi-serializable