Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Raw object and array tranforms for Ember Data
/*
DS.attr('object')
*/
App.ObjectTransform = DS.Transform.extend({
deserialize: function(value) {
if (!$.isPlainObject(value)) {
return {};
} else {
return value;
}
},
serialize: function(value) {
if (!$.isPlainObject(value)) {
return {};
} else {
return value;
}
}
});
/*
DS.attr('array')
*/
App.ArrayTransform = DS.Transform.extend({
deserialize: function(value) {
if (Ember.isArray(value)) {
return Em.A(value);
} else {
return Em.A();
}
},
serialize: function(value) {
if (Ember.isArray(value)) {
return Em.A(value);
} else {
return Em.A();
}
}
});
@NuckChorris

This comment has been minimized.

Copy link

NuckChorris commented Jan 30, 2015

For anyone who comes here and wants it for Ember-CLI, I ported it for you: https://gist.github.com/NuckChorris/927d7d4ba757abd26b30

@spectras

This comment has been minimized.

Copy link

spectras commented Sep 29, 2015

Am I right in assuming this will fail to mark the model as dirty if the array gets updated?

@coryondemand

This comment has been minimized.

Copy link

coryondemand commented Nov 11, 2015

@spectras you are correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.