0
votes

I have an Ember JS survey application built with a Firebase backend (Emberfire adapter).

The following code works correctly when in development:

if(!(_this.currentModel.get('respondents').contains(thisUser)))
{
    thisUser.get('surveysToTake').pushObject(_this.currentModel);
    _this.currentModel.get('respondents').pushObject(thisUser);
    var userResponseSet = _this.store.createRecord('response-set', {
        survey: _this.currentModel,
        respondentid: thisUser
    });
    var respSetSurveyLookupObj = {'surveyId': _this.currentModel.get('id'),
                                     'respSetId': userResponseSet.get('id')};
    if(thisUser.get('respSetSurveyLookup'))
    {
        thisUser.get('respSetSurveyLookup').pushObject(respSetSurveyLookupObj);
    } else {
        thisUser.set('respSetSurveyLookup', [respSetSurveyLookupObj]);
    }
    thisUser.save().then(function(){
        Ember.RSVP.all([_this.currentModel.save(), userResponseSet.save()]).then(function(){
        controller.setProperties({ multipleUsers: '', showAddUsers: false});
        });
    }).catch(function(msg){console.log(msg);});
}

But the moment I do:

ember build -prod

It throws an error when trying to save the user object. The specific place which throws the error is when I try to add to the respSetSurveyLookup array.

Unfortunately, I'm not able to work my way down the stack trace as the error message is in minified JS code.

So my question is, what might cause a user object save to fail only when an ember build is done? Is this an issue that's arising from Ember CLI (which does the build)? Or is it something to do with the Firebase Emberfire adapter?

Additional info: I'm using Ember CLI 1.13.13, Ember 1.13.11 and Ember data 1.13.11.

1
@Piyush Khatri ... thanks for making the code a lot more readable by indenting it. SO rocks!learningMachine
If your saving punch of array items You can approach it like this => Ember.RSVP.all([this.currentModel, userResponseSet].invoke('save'))kris
@kristjanreinhold thanks. that's neat.learningMachine

1 Answers

0
votes

okay ... I think I have a temporary fix and a potential reasoning for the problem. After you do an Ember build and then do the following:

thisUser.get('respSetSurveyLookup').pushObject(respSetSurveyLookupObj);

respSetSurveyLookup which is a regular array gets converted into an Ember array. And when you try to save this, Firebase throws an error (it does not know how to handle an embedded ember array).

The following change appears to fix the problem:

thisUser.get('respSetSurveyLookup').pushObject(respSetSurveyLookupObj);
thisUser.set('respSetSurveyLookup', JSON.parse(JSON.stringify(thisUser.get('respSetSurveyLookup'))));