File tree 2 files changed +10
-5
lines changed
2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -132,10 +132,15 @@ def register_jsonapi_renderer
132
132
133
133
# If it's an empty collection, return it
134
134
many = options [ :is_collection ] || RailsJSONAPI ::Rails . is_collection? ( resource )
135
- if many && !resource . any?
135
+
136
+ # preload data
137
+ data = many ? resource . to_a : resource
138
+
139
+ # return early
140
+ if many && data . empty?
136
141
return options . slice ( :meta , :links ) . merge ( data : [ ] ) . to_json
137
142
end
138
-
143
+
139
144
# get serializer class
140
145
serializer_class = if options . key? ( :serializer_class )
141
146
options . delete ( :serializer_class )
@@ -144,8 +149,8 @@ def register_jsonapi_renderer
144
149
else
145
150
RailsJSONAPI ::Rails . infer_serializer_from_resource ( resource , many )
146
151
end
147
-
148
- serializer_class . new ( resource , options ) . serializable_hash . to_json
152
+
153
+ serializer_class . new ( data , options ) . serializable_hash . to_json
149
154
end
150
155
151
156
end
Original file line number Diff line number Diff line change 1
1
module RailsJSONAPI
2
- VERSION = '0.1.7 '
2
+ VERSION = '0.1.8 '
3
3
end
You can’t perform that action at this time.
0 commit comments