Skip to content

Commit 59a9feb

Browse files
authored
Ensure relationship renders independent of fields (#98)
Explained jsonapi-rb/jsonapi-serializable#102
1 parent 91cf48e commit 59a9feb

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/jsonapi_compliable.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
require 'jsonapi/serializable'
3333
end
3434

35+
# Temporary fix until fixed upstream
36+
# https://github.com/jsonapi-rb/jsonapi-serializable/pull/102
37+
JSONAPI::Serializable::Resource.class_eval do
38+
def requested_relationships(fields)
39+
@_relationships
40+
end
41+
end
42+
3543
require "jsonapi_compliable/extensions/extra_attribute"
3644
require "jsonapi_compliable/extensions/boolean_attribute"
3745
require "jsonapi_compliable/extensions/temp_id"

spec/integration/rails/finders_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ def json
193193
expect(json_included_types).to match_array(%w(books genres))
194194
end
195195

196+
context 'when passing sparse fieldsets on primary data' do
197+
context 'and sideloading' do
198+
it 'is able to sideload without adding the field' do
199+
get :index, params: { fields: { authors: 'first_name' }, include: 'books' }
200+
expect(json['data'][0]['relationships']).to be_present
201+
expect(json_included_types).to match_array(%w(books))
202+
end
203+
end
204+
end
205+
196206
context 'sideloading has_many' do
197207
# TODO: may want to blow up here, only for index action
198208
it 'allows pagination of sideloaded resource' do

0 commit comments

Comments
 (0)