jsonapi-resources 0.10.5 → 0.10.6

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
  SHA256:
3
- metadata.gz: ac8ebf6446cff655aede872afda1f5343ab32a825e7f8be26c56ae1a44a4cdc6
4
- data.tar.gz: 1069433f6a6b65ca6a6b8dd720408ad249df1c18f26858495adc17de6e1aaec1
3
+ metadata.gz: '091836afd689ed975ab1ad2cee54a467a0771cb5ea5b0bfa2055e25531809f74'
4
+ data.tar.gz: 96d46c67f8c88fa3e6d298eac85dc3862bef6feacbe8eddde1515b80e7c8e5a8
5
5
  SHA512:
6
- metadata.gz: 9f603f9d68eb6996f439e63d2ea39c78691555fbb3fcc56c8783c5d8c44c9700c77947d81d8061a8246bb8d230bd150c6e83ef5d846472bab13cc6d10cb7377e
7
- data.tar.gz: cc5dad7fdd043aee7ce42cc51c455a29835b8cb88306a8bd15837105cb6d5ab04d33fc3d68357c85ac1e1a1cd8d11691578deb0a9da3451f02a3141eff76d9df
6
+ metadata.gz: f4dfc6fd61f4a7d27a291626b00c6e5c13cad32be0b73b66e239f254800d73557168470191923cd5bcf29869bfdb1e93a11c4a8b6e3eca25411b1ac8dbc4e24d
7
+ data.tar.gz: e6c699748872330b22ae151082595e48bed10665e9c61c3ba902f585747090e19ab9319776d189bc06fe9ca7797f00467fb08a3e863a4ce7e3b740fd85bc2fe8
@@ -147,9 +147,15 @@ module JSONAPI
147
147
  related_resource_klass = join_details[:related_resource_klass]
148
148
  join_type = relationship_details[:join_type]
149
149
 
150
+ join_options = {
151
+ relationship: relationship,
152
+ relationship_details: relationship_details,
153
+ related_resource_klass: related_resource_klass,
154
+ }
155
+
150
156
  if relationship == :root
151
157
  unless source_relationship
152
- add_join_details('', {alias: resource_klass._table_name, join_type: :root})
158
+ add_join_details('', {alias: resource_klass._table_name, join_type: :root, join_options: join_options})
153
159
  end
154
160
  next
155
161
  end
@@ -163,7 +169,7 @@ module JSONAPI
163
169
  options: options)
164
170
  }
165
171
 
166
- details = {alias: self.class.alias_from_arel_node(join_node), join_type: join_type}
172
+ details = {alias: self.class.alias_from_arel_node(join_node), join_type: join_type, join_options: join_options}
167
173
 
168
174
  if relationship == source_relationship
169
175
  if relationship.polymorphic? && relationship.belongs_to?
@@ -324,6 +324,11 @@ module JSONAPI
324
324
  records = records.joins_left(relation_name)
325
325
  end
326
326
  end
327
+
328
+ if relationship.use_related_resource_records_for_joins
329
+ records = records.merge(self.records(options))
330
+ end
331
+
327
332
  records
328
333
  end
329
334
 
@@ -51,8 +51,8 @@ module JSONAPI
51
51
  @fetchable_fields = Set.new(fetchable_fields)
52
52
 
53
53
  # Relationships left uncompiled because we'll often want to insert included ids on retrieval
54
- @relationships = relationships
55
-
54
+ # Remove the data since that should not be cached
55
+ @relationships = relationships&.transform_values {|v| v.delete_if {|k, _v| k == 'data'} }
56
56
  @links_json = CompiledJson.of(links_json)
57
57
  @attributes_json = CompiledJson.of(attributes_json)
58
58
  @meta_json = CompiledJson.of(meta_json)
@@ -39,7 +39,8 @@ module JSONAPI
39
39
  :default_resource_cache_field,
40
40
  :resource_cache_digest_function,
41
41
  :resource_cache_usage_report_function,
42
- :default_exclude_links
42
+ :default_exclude_links,
43
+ :use_related_resource_records_for_joins
43
44
 
44
45
  def initialize
45
46
  #:underscored_key, :camelized_key, :dasherized_key, or custom
@@ -158,6 +159,11 @@ module JSONAPI
158
159
  # and relationships. Accepts either `:default`, `:none`, or array containing the
159
160
  # specific default links to exclude, which may be `:self` and `:related`.
160
161
  self.default_exclude_links = :none
162
+
163
+ # Use a related resource's `records` when performing joins. This setting allows included resources to account for
164
+ # permission scopes. It can be overridden explicitly per relationship. Furthermore, specifying a `relation_name`
165
+ # on a relationship will cause this setting to be ignored.
166
+ self.use_related_resource_records_for_joins = true
161
167
  end
162
168
 
163
169
  def cache_formatters=(bool)
@@ -299,6 +305,8 @@ module JSONAPI
299
305
  attr_writer :resource_cache_usage_report_function
300
306
 
301
307
  attr_writer :default_exclude_links
308
+
309
+ attr_writer :use_related_resource_records_for_joins
302
310
  end
303
311
 
304
312
  class << self
@@ -3,7 +3,7 @@ module JSONAPI
3
3
  attr_reader :acts_as_set, :foreign_key, :options, :name,
4
4
  :class_name, :polymorphic, :always_include_optional_linkage_data,
5
5
  :parent_resource, :eager_load_on_include, :custom_methods,
6
- :inverse_relationship, :allow_include
6
+ :inverse_relationship, :allow_include, :use_related_resource_records_for_joins
7
7
 
8
8
  attr_writer :allow_include
9
9
 
@@ -23,6 +23,15 @@ module JSONAPI
23
23
  @polymorphic_types ||= options[:polymorphic_relations]
24
24
  end
25
25
 
26
+ use_related_resource_records_for_joins_default = if options[:relation_name]
27
+ false
28
+ else
29
+ JSONAPI.configuration.use_related_resource_records_for_joins
30
+ end
31
+
32
+ @use_related_resource_records_for_joins = options.fetch(:use_related_resource_records_for_joins,
33
+ use_related_resource_records_for_joins_default) == true
34
+
26
35
  @always_include_optional_linkage_data = options.fetch(:always_include_optional_linkage_data, false) == true
27
36
  @eager_load_on_include = options.fetch(:eager_load_on_include, false) == true
28
37
  @allow_include = options[:allow_include]
@@ -1,5 +1,5 @@
1
1
  module JSONAPI
2
2
  module Resources
3
- VERSION = '0.10.5'
3
+ VERSION = '0.10.6'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi-resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.5
4
+ version: 0.10.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Gebhardt
8
8
  - Larry Gebhardt
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-05-19 00:00:00.000000000 Z
12
+ date: 2022-02-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -232,7 +232,7 @@ homepage: https://github.com/cerebris/jsonapi-resources
232
232
  licenses:
233
233
  - MIT
234
234
  metadata: {}
235
- post_install_message:
235
+ post_install_message:
236
236
  rdoc_options: []
237
237
  require_paths:
238
238
  - lib
@@ -247,8 +247,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
247
247
  - !ruby/object:Gem::Version
248
248
  version: '0'
249
249
  requirements: []
250
- rubygems_version: 3.1.4
251
- signing_key:
250
+ rubygems_version: 3.1.6
251
+ signing_key:
252
252
  specification_version: 4
253
253
  summary: Easily support JSON API in Rails.
254
254
  test_files: []