diff --git a/lib/sinja.rb b/lib/sinja.rb index 5d20636..e77245e 100644 --- a/lib/sinja.rb +++ b/lib/sinja.rb @@ -157,6 +157,15 @@ def data end end + def included + @included ||= {} + @included[request.path] ||= begin + deserialize_request_body.fetch(:included, nil) + rescue NoMethodError, KeyError + raise BadRequestError, 'Malformed {json:api} request payload' + end + end + def normalize_filter_params return {} unless params[:filter]&.any? diff --git a/lib/sinja/helpers/relationships.rb b/lib/sinja/helpers/relationships.rb index e7579ca..90f9ef1 100644 --- a/lib/sinja/helpers/relationships.rb +++ b/lib/sinja/helpers/relationships.rb @@ -23,6 +23,7 @@ def dispatch_relationship_requests!(id, methods: {}, **opts) rels = data.fetch(:relationships, {}).to_a rels.each do |rel, body, rel_type=nil, count=0| rel_type ||= settings._resource_config[:has_one].key?(rel) ? :has_one : :has_many + body = body.merge(included: included) if included code, _, *json = dispatch_relationship_request id, rel, opts.merge(:body=>body, :method=>methods.fetch(rel_type, :patch))