graphiti 1.0.alpha.11 → 1.0.alpha.12

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: 8b451b3a2214bfee53214b84b53455b40df0a555
4
- data.tar.gz: f3208a80a842591303a7f091f6544edb1c26ac3b
3
+ metadata.gz: 5ce517d6401bea528533904e46403edc173ff484
4
+ data.tar.gz: 2dbb938df50136bcd97d3cab586252c4789e10d4
5
5
  SHA512:
6
- metadata.gz: 877bbfdfc4af3bd92c6ff59bc932d5dc1022a9fee8ed2d138da4045cd01c7c5249e2ef06c993e83084fce6c5fa89f7f54ae6a05ca778750d4eb95e7ff01ee887
7
- data.tar.gz: 075a9538fd31ecc16c84a317d3d80445d447de5598eb4bd23afa493c482845789fe33b66af0b4c699c976e513e1f9bd721096d7b0b7018303d6b56fa1d9420a4
6
+ metadata.gz: 62550f735f9afc8bfcb68261e9a671c8f066245f15931ecbc2497fbe317ec720b6898aa1784daa01c7aed03f39565183c07f43c14d7cd5f0fe4d777e08137ebb
7
+ data.tar.gz: b006db1dd79aa9f3541ab1a6960468c919d19378b9ff330cbd565c4714bd4d290b0b86778e0f94b51e2101108ad85bda12f80e7ed45576c9b8208286264ad866
data/lib/graphiti.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'json'
2
2
  require 'forwardable'
3
3
  require 'active_support/core_ext/string'
4
+ require 'active_support/core_ext/enumerable'
4
5
  require 'active_support/core_ext/class/attribute'
5
6
  require 'active_support/core_ext/hash/conversions' # to_xml
6
7
  require 'active_support/concern'
@@ -173,13 +173,11 @@ module Graphiti
173
173
  associated |= relevant_children
174
174
  associate_all(parent, relevant_children)
175
175
  else
176
- associated << relevant_children
176
+ associated << relevant_children if relevant_children
177
177
  associate(parent, relevant_children)
178
178
  end
179
179
  end
180
- (children - associated).each do |unassigned|
181
- children.delete(unassigned)
182
- end
180
+ children.replace(associated)
183
181
  end
184
182
 
185
183
  def resolve(parents, query)
@@ -24,7 +24,8 @@ class Graphiti::Sideload::BelongsTo < Graphiti::Sideload
24
24
  end
25
25
 
26
26
  def assign_each(parent, children)
27
- children.find { |c| c.send(primary_key) == parent.send(foreign_key) }
27
+ children_hash = children.index_by(&primary_key)
28
+ children_hash[parent.send(foreign_key)]
28
29
  end
29
30
 
30
31
  def ids_for_parents(parents)
@@ -15,6 +15,7 @@ class Graphiti::Sideload::HasMany < Graphiti::Sideload
15
15
  end
16
16
 
17
17
  def assign_each(parent, children)
18
- children.select { |c| c.send(foreign_key) == parent.send(primary_key) }
18
+ children_hash = children.group_by(&foreign_key)
19
+ children_hash[parent.send(primary_key)] || []
19
20
  end
20
21
  end
@@ -4,6 +4,8 @@ class Graphiti::Sideload::HasOne < Graphiti::Sideload::HasMany
4
4
  end
5
5
 
6
6
  def assign_each(parent, children)
7
- children.find { |c| c.send(foreign_key) == parent.send(primary_key) }
7
+ children_hash = children.group_by(&foreign_key)
8
+ result = children_hash[parent.send(primary_key)] || []
9
+ result[0]
8
10
  end
9
11
  end
@@ -1,3 +1,3 @@
1
1
  module Graphiti
2
- VERSION = "1.0.alpha.11"
2
+ VERSION = "1.0.alpha.12"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiti
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.alpha.11
4
+ version: 1.0.alpha.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond