Skip to content

Commit 0b9ead2

Browse files
committed
allowing resources to be deleted with a custom primary key
1 parent 238365e commit 0b9ead2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/json_api_client/resource.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def as_relation
394394
#
395395
# @return [Hash] Representation of this object as JSONAPI object
396396
def as_json_api(*)
397-
attributes.slice(:id, :type).tap do |h|
397+
attributes.slice(self.class.primary_key, :type).tap do |h|
398398
relationships_for_serialization.tap do |r|
399399
h[:relationships] = self.class.key_formatter.format_keys(r) unless r.empty?
400400
end
@@ -403,11 +403,11 @@ def as_json_api(*)
403403
end
404404

405405
def as_json(*)
406-
attributes.slice(:id, :type).tap do |h|
406+
attributes.slice(self.class.primary_key, :type).tap do |h|
407407
relationships.as_json.tap do |r|
408408
h[:relationships] = r unless r.empty?
409409
end
410-
h[:attributes] = attributes.except(:id, :type).as_json
410+
h[:attributes] = attributes.except(self.class.primary_key, :type).as_json
411411
end
412412
end
413413

@@ -504,7 +504,7 @@ def reset_request_select!(*resource_types)
504504
end
505505

506506
def path_attributes
507-
_belongs_to_params.merge attributes.slice('id').symbolize_keys
507+
_belongs_to_params.merge attributes.slice( self.class.primary_key ).symbolize_keys
508508
end
509509

510510
protected

0 commit comments

Comments
 (0)