Skip to content

Commit

Permalink
Merge pull request cerebris#961 from cerebris/fix960
Browse files Browse the repository at this point in the history
Default `id` to being a read only attribute
  • Loading branch information
dgeb authored Jan 19, 2017
2 parents 06b5f43 + 4f51331 commit 5465aba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/jsonapi/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,9 @@ def inherited(subclass)
type = subclass.name.demodulize.sub(/Resource$/, '').underscore
subclass._type = type.pluralize.to_sym

subclass.attribute :id, format: :id
unless subclass._attributes[:id]
subclass.attribute :id, format: :id, readonly: true
end

check_reserved_resource_name(subclass._type, subclass.name)
end
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ def self.updatable_fields(context)
end

def self.creatable_fields(context)
super(context) - [:subject, :id]
super(context) - [:subject]
end

def self.sortable_fields(context)
Expand All @@ -1132,6 +1132,7 @@ class HairCutResource < JSONAPI::Resource

class IsoCurrencyResource < JSONAPI::Resource
attributes :name, :country_name, :minor_unit
attribute :id, format: :id, readonly: false

filter :country_name

Expand Down

0 comments on commit 5465aba

Please sign in to comment.