Reload of a model does not reset empty properties


#1

Hey!

We are building an admin-interface for a multi-language web app. With the admin-interface the user is able to input data in different languages. The user can switch the input-language of the form on the right top of the view. After the user switched the language I want the model to reload and I want that the form is populated with the data of the actual input-language. I tried it the following way:

in MultiLanguageController.js:

switchLanguage: function (newLang) {
    this.get('model').reload({contentLanguage: newLang}).then(function () {
        // SUCCESS
    }, function() {
        // FAILURE
    });
}

and in adapters/application.js:

export default DS.RESTAdapter.extend({
    host: //URL,
    buildURL: function (type, id, snapshot) {
        var url = this._super(type, id, snapshot);
        if (!snapshot || !snapshot.record) { 
            return url;
        }
        var record = snapshot.record;
        var queryParams = Ember.get(record, 'queryParams');
        if (!Ember.isEmpty(queryParams)) {
            for (var key in queryParams) {
                if (queryParams.hasOwnProperty(key)) {
                    var seperator = (url.indexOf('?') === -1) ? '?' : '&';
                    url += seperator + key + '=' + queryParams[key];
                }
            }
        }
        return url;
    }
});

The backend serves the data in the right way and for properties which are set in the language this approach works quite nice but properties which are not set should be cleared. Is there any chance to achieve this with reload?

For example, the user adds data for a product in english:

{ label: "Car", price: 15000, width: 1800, height: 1500, depth: 3500 }

Then the user switches the form to german. The server responds with:

{ label: "", price: 15000, width: 1800, height: 1500, depth: 3500 }

Now the label field in the form should be empty. Can I achieve this somehow?

Hope you can help me :smile: