If transmitting an empty array, mark it as such

This commit is contained in:
Robin Ward 2015-01-02 16:12:06 -05:00
parent 6f72f265cb
commit 5beac44731
1 changed files with 12 additions and 0 deletions

View File

@ -357,6 +357,18 @@ Discourse.Topic.reopenClass({
},
update: function(topic, props) {
props = JSON.parse(JSON.stringify(props)) || {};
// Annoyingly, empty arrays are not sent across the wire. This
// allows us to make a distinction between arrays that were not
// sent and arrays that we specifically want to be empty.
Object.keys(props).forEach(function(k) {
var v = props[k];
if (v instanceof Array && v.length === 0) {
props[k + '_empty_array'] = true;
}
});
return Discourse.ajax(topic.get('url'), { type: 'PUT', data: props }).then(function(result) {
// The title can be cleaned up server side