Ember-cli implements a custom serializer

In an Ember-cli project with Rails 4 support - I need to be able to save (and eventually read) nested data. The data model is straightforward ...

Survey
  name: string

Question:
  survey_id: integer
  question_type_id: integer
  text: string

Answer: 
  question_id: integer
  text: string

A Survey hasMany Questions.  Each Question hasMany Answers

      

I am trying to figure out how to write a custom Survey serializer. Based on my research, I know that I need to extend DS.JSONSerializer, but I'm not sure what to do next. Any help would be greatly appreciated.

thank

+3


source to share


1 answer


Ember-cli comes with a generator to run serializers. You can start it with

$ ember g serializer Survey

      

which produces:

version: 0.0.40
installing
  create app/serializers/survey.js
  create tests/unit/serializers/survey-test.js

      



Out of the box, the serializer will look like this:

import DS from 'ember-data';

export default DS.RESTSerializer.extend({
});

      

Now you can customize it based on your needs. Since you haven't specified what type of customization you want to do, you can read the documentation . In particular, you can check the section on customization .

+5


source







All Articles