Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to access included in relation sideload #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/sinja.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
1 change: 1 addition & 0 deletions lib/sinja/helpers/relationships.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down