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 +4 -4
- data/lib/fields/serializer/action_controller.rb +3 -3
- data/lib/fields/serializer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb0b4cfe21d5120c6d67a4ab594a5390fef876bf
|
4
|
+
data.tar.gz: d0da66e1a059349ef38c38fdd193e218e9088da3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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)
|
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.
|
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:
|
13
|
+
date: 2018-01-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|