fields-serializer 0.6.4 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30960fcbcf7ca34b2afab4071e75e25a5dff9985
4
- data.tar.gz: 0caa871a6b14bdac321bc4f3b53003d4ea1d398d
3
+ metadata.gz: eb0b4cfe21d5120c6d67a4ab594a5390fef876bf
4
+ data.tar.gz: d0da66e1a059349ef38c38fdd193e218e9088da3
5
5
  SHA512:
6
- metadata.gz: 2302de02d444424bfc02b88d7ccf750f20f003ef649d930dab22b027cbc9cf02be5582b8caf400dd63c6e6f385d8c45b00a7f42c6f2993f536823f3a41996507
7
- data.tar.gz: 4c96cf021d40bc3f5162b1e4fc37c7917b9c5baa86dbb6aa301d6f58b4c0b07ef57c4706ef0c7cc6204292b11e4515b536cb1f3ff134c4407d2d7329649d6f8a
6
+ metadata.gz: d07b619c08d353991331093e080fc6d59bb6fd3cab809fffd8746085f0fd36245e878f077a795ca189c2aa6d33145b7f09ac8e898cc53e17be44bb91e9294cfa
7
+ data.tar.gz: c696c4967f39bbc5813add23ea905ae34e111f6192b3abae01d97cbe9fcfa7fac2596013e7dd5964ba9f8b92d8910a099e1a80bcb9dc041c35fe21f52b527207
@@ -5,18 +5,18 @@ module Fields
5
5
  module ActionController
6
6
  extend ActiveSupport::Concern
7
7
 
8
-
9
8
  # Render the result of an ActiveRecord::Relation query including only the fields specified
10
9
  #
11
10
  # @param [ActiveRecord::Relation] query - The query to render in json
11
+ # @param [Boolean] optimize_query - Add outer joins to the query to prevent a db query per serialized object.
12
12
  # @option options [Array] :fields - The list of fields to return in json api syntax
13
13
  # @option options [Class] :model_class - The model class of the objects to be queried to optimize db hits.
14
14
  # @option options [Hash] :options - Any other valid option to render method.
15
- def render_json_fields(query, **options)
15
+ def render_json_fields(query, optimize_query: true, **options)
16
16
  fields = options.delete(:fields)
17
17
  model_class = options.delete(:model_class)
18
18
  if fields.present?
19
- query = query.includes(*model_class.fields_to_includes(fields))
19
+ query = query.includes(*model_class.fields_to_includes(fields)) if optimize_query
20
20
  options.merge!(each_serializer: model_class.fields_serializer(fields), include: "**")
21
21
  end
22
22
  render options.merge!(json: query.to_a)
@@ -1,5 +1,5 @@
1
1
  module Fields
2
2
  module Serializer
3
- VERSION = "0.6.4"
3
+ VERSION = "0.7.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fields-serializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stuart Chinery
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2017-12-20 00:00:00.000000000 Z
13
+ date: 2018-01-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler