jsonapi_compliable 0.11.15 → 0.11.16

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: 3948d56bb234ee8a53b3697830eec3a1e556baef
4
- data.tar.gz: c3f2004adda3e41025714b46609db656bd2dce4a
3
+ metadata.gz: 91b4575901e4872810f2439548136f4798893a9a
4
+ data.tar.gz: 206d39a17e6cd69449ef459447f33ef7db361c62
5
5
  SHA512:
6
- metadata.gz: 7430a24b6b1e5c03d13c6ac5e1bb16a2d443f5028a5d246ce7658d26d06828d5ce645d038bf3775a791b005e450b51c15df35258c35ef83297dadc48ae1ceddd
7
- data.tar.gz: c3bee1548419c881cdb9483635473ce2cf630ff8dec548aa72e3731134a6c95e1a92c127094893010eefdc144b026faf4af247260b4223a1ee6e18784b178b2d
6
+ metadata.gz: 780451a9a115ea499c590ede80da6cde4dd680e22776ad4df06aca54e9e7bb119e8fd492ba0f21587cd9ac907cf9f4213019d225f3de9c051067f26efd6f49b3
7
+ data.tar.gz: a55448c5e88e2044e678b0b4fbdce36d79f79609a116f22a9cbb933e6781c5fefebc27727e28db2b5889808e7a822d0469608ef137a9ccf344263942d888ba60
@@ -53,7 +53,15 @@ module JsonapiCompliable
53
53
  _scope.call.where(foreign_key => parent_ids.uniq.compact)
54
54
  end
55
55
 
56
+ # The 'assigned' code here is to remove all children that do not
57
+ # get assigned. This is because there is no 'limit(1)' in the query.
58
+ # If we did 'limit(1)' for the query, it wouldn't work for index
59
+ # actions (only 1 would come back, when we want one *per result*).
60
+ #
61
+ # Instead, avoid pagination in the query, assign only one result, and
62
+ # remove anything else. This is more or less what AR does.
56
63
  assign do |parents, children|
64
+ assigned = []
57
65
  parents.each do |parent|
58
66
  parent.association(association_name).loaded!
59
67
  relevant_child = children.find { |c| c.send(foreign_key) == parent.send(primary_key) }
@@ -65,6 +73,10 @@ module JsonapiCompliable
65
73
  association.send(:set_owner_attributes, relevant_child)
66
74
  association.send(:set_inverse_instance, relevant_child)
67
75
  association.send(:target=, relevant_child)
76
+ assigned << relevant_child
77
+ end
78
+ (children - assigned).each do |unassigned|
79
+ children.delete(unassigned)
68
80
  end
69
81
  end
70
82
 
@@ -64,6 +64,7 @@ module JsonapiCompliable
64
64
  []
65
65
  else
66
66
  resolved = @resource.resolve(@object)
67
+ yield resolved if block_given?
67
68
  sideload(resolved, query_hash[:include]) if query_hash[:include]
68
69
  resolved
69
70
  end
@@ -399,8 +399,9 @@ module JsonapiCompliable
399
399
  def resolve_basic(parents, query, namespace)
400
400
  sideload_scope = scope_proc.call(parents)
401
401
  sideload_scope = Scope.new(sideload_scope, resource_class.new, query, default_paginate: false, namespace: namespace)
402
- sideload_results = sideload_scope.resolve
403
- assign_proc.call(parents, sideload_results)
402
+ sideload_scope.resolve do |sideload_results|
403
+ assign_proc.call(parents, sideload_results)
404
+ end
404
405
  end
405
406
  end
406
407
  end
@@ -1,3 +1,3 @@
1
1
  module JsonapiCompliable
2
- VERSION = "0.11.15"
2
+ VERSION = "0.11.16"
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.15
4
+ version: 0.11.16
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-05-23 00:00:00.000000000 Z
12
+ date: 2018-05-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jsonapi-serializable