Search code examples
ember.jsember-dataactivemodelactive-model-serializers

How to prevent Ember Data from saving a read-only attribute for ActiveModelSerializer


I am trying to use the {readOnly: true} functionality with ActiveModelSerializer by customizing the serialize method to ignore readOnly attributes like this for JSONAPISerializer or this for RESTSerializer, to prematurely save on upload bandwidth.

Does anyone know if something similar can be done with ActiveModelSerializer?


Solution

  • Both ActiveModelSerializer and JSONAPISerializer extends JSONSerializer. serializeAttribute method is inherited from JSONSerializer. So I don't see any reason you can't adopt the solution given in this stackoverflow question you already mentioned.

    The other answer on stackoverflow relies on a very old API version of RESTSerializer which has been removed before ember-data 1.x release. This has also been mentioned in another answer to same question.