3
votes

I'm using the default RESTAdapter with the ActiveModelAdapter, and I want to include a JSON object in a particular model.
eg:

App.Game = DS.Model.extend(
  name: attr('string')
  options: attr('raw') # This should be a JSON object
)

After reading ember-data/TRANSITION.md.
I've used the same transformer from the example:

App.RawTransform = DS.Transform.extend({
  deserialize: function(serialized) {
    return serialized;
  },
  serialize: function(deserialized) {
    return deserialized;
  }
});

When I've tried to create an Game instance model and save it, the options attribute in the POST data was "null"(string type).

App.GamesController = Ember.ObjectController.extend(
  actions:
    add_new: ->
      game = this.get('model')
      game.set('options', {max_time: 15, max_rounds: 5})
      game.save()
)

What am I missing here?

1
Before you do game.save() are you sure that property "options" is set? - Andriy Buday

1 Answers

6
votes

Probably you need to register your transform:

App = Ember.Application.create();

App.RawTransform = DS.Transform.extend({
  deserialize: function(serialized) {
    return serialized;
  },
  serialize: function(deserialized) {
    return deserialized;
  }
});

App.initializer({
  name: "raw-transform",

  initialize: function(container, application) {
    application.register('transform:raw', App.RawTransform);      
  }
});

I hope it helps