Skip to content

Commit

Permalink
Extract included object base to a method
Browse files Browse the repository at this point in the history
  • Loading branch information
nikajukic committed May 25, 2021
1 parent 48b45f7 commit b35145c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/jsonapi_parameters/default_handlers/base_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@ def find_included_object(related_id:, related_type:)
end

def build_included_object(included_object, related_id)
{ **(included_object[:attributes] || {}) }.tap do |body|
included_object_base(included_object).tap do |body|
body[:id] = related_id unless client_generated_id?(related_id)
body[:relationships] = included_object[:relationships] if included_object.key?(:relationships) # Pass nested relationships
end
end

def included_object_base(included_object)
{ **(included_object[:attributes] || {}) }
end

def client_generated_id?(related_id)
related_id.to_s.starts_with?(JsonApi::Parameters.client_id_prefix)
end
Expand Down

0 comments on commit b35145c

Please sign in to comment.